namespace RO.Rule3
{
	using System;
	using System.Data;
	using System.IO;
	using System.Text;
	using System.Text.RegularExpressions;
    using System.Linq;
    using System.Collections.Generic;
    using RO.Common3;
	using RO.Common3.Data;
	using RO.SystemFramewk;
	using RO.Access3;
    
	public class GenScreensRules
	{
        private GenScreensAccessBase GetGenScreensAccess(int CommandTimeout = 1800)
        {
            if ((Config.DesProvider  ?? "").ToLower() != "odbc")
            {
                return new GenScreensAccess();
            }
            else
            {
                return new RO.Access3.Odbc.GenScreensAccess();
            }
        }
        private AdminAccessBase GetAdminAccess(int CommandTimeout = 1800)
        {
            if ((Config.DesProvider  ?? "").ToLower() != "odbc")
            {
                return new AdminAccess(CommandTimeout);
            }
            else
            {
                return new RO.Access3.Odbc.AdminAccess(CommandTimeout);
            }
        }
        private RobotAccessBase GetRobotAccess(int CommandTimeout = 1800)
        {
            if ((Config.DesProvider  ?? "").ToLower() != "odbc")
            {
                return new RobotAccess();
            }
            else
            {
                return new RO.Access3.Odbc.RobotAccess();
            }
        }
        private string AlignmentTranslate(string justify)
        {
            if (justify == "C") return "text-align:center;";
            else if (justify == "R") return "text-align:right;";
            else if (justify == "L") return "text-align:left;";
            else return "";
        }
        private string WrapConditionalWebRule(string blockIndent, DataRowView drv)
        {
            string companyId = drv["ForCompanyId"].ToString();
            string webRuleId = drv["WebRuleId"].ToString();
            string webRule = drv["WebRuleProg"].ToString().Replace("\r\n","\n").Replace("\r","\n");
            if (string.IsNullOrEmpty(companyId))
            {
                return webRule.Replace("\n",Environment.NewLine) + Environment.NewLine;
            }
            string[] srcLines = webRule.Split(new char[] { '\n' });
            //string oneTab = "\\t";
            //string initBlockIndent = srcLines.Length > 0 ? String.Concat(srcLines[0].TakeWhile(c => char.IsWhiteSpace(c))) : "";
            //Regex leadingSpace = new Regex("^" + initBlockIndent);
            //srcLines = srcLines.Select(s => blockIndent + oneTab + leadingSpace.Replace(s, "")).ToArray();
            return
                (blockIndent + "if (RunWebRule(\"" + companyId + "\", " + webRuleId + "))" + "\n"
                + blockIndent + "{" + "\n"
                + string.Join("\n", srcLines) + "\n"
                + blockIndent + "}" + "\n").Replace("\n", Environment.NewLine) + Environment.NewLine;
        }
        public bool DeleteProgram(string programName, Int32 screenId, string appDatabase, string multiDesignDb, string sysProgram, CurrPrj CPrj, CurrSrc CSrc, CurrTar CTar)
		{
			try
			{
				// Delete source client tier programs:
				DeleteProgC(programName, screenId, CPrj, CPrj.SrcClientProgramPath, CPrj.SrcClientFrwork);
				// Delete target client tier programs:
				if (CPrj.SrcClientProgramPath != CPrj.TarClientProgramPath)
				{
					DeleteProgC(programName, screenId, CPrj, CPrj.TarClientProgramPath, CPrj.TarClientFrwork);
				}
				// Delete web service tier programs:
				//DeleteProgW(programName, screenId, CPrj, CPrj.SrcWsProgramPath, CPrj.SrcClientFrwork);
				// Delete target client tier programs:
                //if (CPrj.SrcWsProgramPath != CPrj.TarWsProgramPath)
                //{
                //    DeleteProgW(programName, screenId, CPrj, CPrj.TarWsProgramPath, CPrj.TarClientFrwork);
                //}
				// Delete source rule tier programs:
				//DeleteProgR(programName, screenId, CPrj, CSrc, CPrj.SrcRuleProgramPath, CPrj.SrcRuleFrwork);
				// Delete target rule tier programs:
                //if (CPrj.SrcRuleProgramPath != CPrj.TarRuleProgramPath)
                //{
                //    DeleteProgR(programName, screenId, CPrj, CSrc, CPrj.TarRuleProgramPath, CPrj.TarRuleFrwork);
                //}
				// Delete source data tier programs:
				DeleteProgD(CSrc.SrcDbDatabase, appDatabase, CPrj.SrcDesDatabase, programName, screenId, multiDesignDb, sysProgram, CSrc.SrcConnectionString, CSrc.SrcDbPassword);
				// Delete target data tier programs:
				if (CTar.TarDbServer != CSrc.SrcDbServer && CPrj.SrcDesProviderCd == "M")
				{
					DeleteProgD(CTar.TarDbDatabase, appDatabase, CPrj.TarDesDatabase, programName, screenId, multiDesignDb, sysProgram, CTar.TarConnectionString, CTar.TarDbPassword);
				}
			}
			catch (Exception e) {ApplicationAssert.CheckCondition(false,"","",e.Message); return false;}
			return true;
		}

		private void DeleteProgC(string programName, Int32 screenId, CurrPrj CPrj, string clientProgramPath, string clientFrwork)
		{
			FileInfo fi = null;
            // normalize expected value
            clientProgramPath = clientProgramPath.EndsWith("\\") || clientProgramPath.EndsWith("/") ? clientProgramPath : clientProgramPath + "\\";
            fi = new FileInfo(clientProgramPath + programName + ".aspx"); if (fi.Exists) { fi.Delete(); }
			fi = new FileInfo(clientProgramPath + programName + ".aspx.cs"); if (fi.Exists) {fi.Delete();}
			fi = new FileInfo(clientProgramPath + @"modules\" + programName + "Module.ascx"); if (fi.Exists) {fi.Delete();}
			fi = new FileInfo(clientProgramPath + @"modules\" + programName + "Module.ascx.cs"); if (fi.Exists) {fi.Delete();}
		}

        //private void DeleteProgW(string programName, Int32 screenId, CurrPrj CPrj, string wsProgramPath, string clientFrwork)
        //{
        //    FileInfo fi = null;
        //    fi = new FileInfo(wsProgramPath + programName + "Ws.asmx"); if (fi.Exists) { fi.Delete(); }
        //}

        //private void DeleteProgR(string programName, Int32 screenId, CurrPrj CPrj, CurrSrc CSrc, string ruleProgramPath, string ruleFrwork)
        //{
        //    Robot.ModifyCsproj(true, ruleProgramPath + "Service" + CSrc.SrcSystemId.ToString() + "\\Service" + CSrc.SrcSystemId.ToString() + ".csproj", programName + "Ws.cs", string.Empty, ruleFrwork);
        //    Robot.ModifyCsproj(true, ruleProgramPath + "Facade" + CSrc.SrcSystemId.ToString() + "\\Facade" + CSrc.SrcSystemId.ToString() + ".csproj", programName + "System.cs", string.Empty, ruleFrwork);
        //    Robot.ModifyCsproj(true, ruleProgramPath + "Rule" + CSrc.SrcSystemId.ToString() + "\\Rule" + CSrc.SrcSystemId.ToString() + ".csproj", programName + "Rules.cs", string.Empty, ruleFrwork);
        //    Robot.ModifyCsproj(true, ruleProgramPath + "Access" + CSrc.SrcSystemId.ToString() + "\\Access" + CSrc.SrcSystemId.ToString() + ".csproj", programName + "Access.cs", string.Empty, ruleFrwork);
        //    Robot.ModifyCsproj(true, ruleProgramPath + "Common" + CSrc.SrcSystemId.ToString() + "\\Common" + CSrc.SrcSystemId.ToString() + ".csproj", @"Data\" + programName + screenId.ToString() + ".cs", string.Empty, ruleFrwork);
        //    Robot.ModifyCsproj(true, ruleProgramPath + "Common" + CSrc.SrcSystemId.ToString() + "\\Common" + CSrc.SrcSystemId.ToString() + ".csproj", @"Data\" + programName + screenId.ToString() + "In.cs", string.Empty, ruleFrwork);
        //    FileInfo fi = null;
        //    fi = new FileInfo(ruleProgramPath + "Service" + CSrc.SrcSystemId.ToString() + "\\" + programName + "Ws.cs"); if (fi.Exists) { fi.Delete(); }
        //    fi = new FileInfo(ruleProgramPath + "Facade" + CSrc.SrcSystemId.ToString() + "\\" + programName + "System.cs"); if (fi.Exists) { fi.Delete(); }
        //    fi = new FileInfo(ruleProgramPath + "Rule" + CSrc.SrcSystemId.ToString() + "\\" + programName + "Rules.cs"); if (fi.Exists) {fi.Delete();}
        //    fi = new FileInfo(ruleProgramPath + "Access" + CSrc.SrcSystemId.ToString() + "\\" + programName + "Access.cs"); if (fi.Exists) {fi.Delete();}
        //    fi = new FileInfo(ruleProgramPath + "Common" + CSrc.SrcSystemId.ToString() + "\\Data\\" + programName + screenId.ToString() + ".cs"); if (fi.Exists) {fi.Delete();}
        //    fi = new FileInfo(ruleProgramPath + "Common" + CSrc.SrcSystemId.ToString() + "\\Data\\" + programName + screenId.ToString() + "In.cs"); if (fi.Exists) {fi.Delete();}
        //}

		private void DeleteProgD(string dbDatabase, string appDatabase, string desDatabase, string programName, Int32 screenId, string multiDesignDb, string sysProgram, string dbConnectionString, string dbPassword)
		{
			using (GenScreensAccessBase dac = GetGenScreensAccess())
			{
				dac.DelScreenDel(dbDatabase, appDatabase, desDatabase, programName, screenId, multiDesignDb, sysProgram, dbConnectionString, dbPassword);
			}
			DataView dvCri = null;
			using (GenScreensAccessBase dac = GetGenScreensAccess())
			{
				dvCri = new DataView(dac.GetScreenCriDel(screenId, dbConnectionString, dbPassword));
			}
			if (dvCri != null)
			{
				foreach (DataRowView drv in dvCri)
				{
					using (GenScreensAccessBase dac = GetGenScreensAccess())
					{
						dac.DelScreenCriDel(appDatabase, drv["ProcedureName"].ToString(), dbConnectionString, dbPassword);
					}
				}
			}
		}

		public bool CreateProgram(Int32 screenId, string screenTitle, string dbAppDatabase, CurrPrj CPrj, CurrSrc CSrc, CurrTar CTar, string dbConnectionString, string dbPassword)
		{
			DataTable dt = null;
			using (GenScreensAccessBase dac = GetGenScreensAccess())
			{
				dt = dac.GetScreenById(screenId, CPrj, CSrc);
			}
            if (dt.Rows[0]["GenerateSc"].ToString() == "Y" || dt.Rows[0]["GenerateSr"].ToString() == "Y")
			{
				DataView dv = null;
				using (GenScreensAccessBase dac = GetGenScreensAccess())
				{
					dv = new DataView(dac.GetScreenColumns(screenId, CPrj, CSrc));
                    if (!dv.Table.AsEnumerable().Any(x => x.Field<string>("MasterTable") == "Y" && x.Field<string>("PrimaryKey") == "Y"))
                    {
                        throw new Exception(screenTitle + ": must include the master table primary key column");
                    }
                    if ("I2".IndexOf(dt.Rows[0]["ScreenTypeName"].ToString()) >= 0 && !dv.Table.AsEnumerable().Any(x => x.Field<string>("MasterTable") == "N" && x.Field<string>("PrimaryKey") == "Y"))
                    {
                        throw new Exception(screenTitle + ": must include the child table primary key column");
                    }
                }
				DataView dvTab = null;
				if ("I1,I2".IndexOf(dt.Rows[0]["ScreenTypeName"].ToString()) >= 0)
				{
					using (GenScreensAccessBase dac = GetGenScreensAccess())
					{
						dvTab = new DataView(dac.GetDistinctScreenTab(screenId, CPrj, CSrc));
					}
				}
				DataView dvCri = null;
				using (GenScreensAccessBase dac = GetGenScreensAccess())
				{
					dvCri = new DataView(dac.GetScreenCriteria(screenId, CPrj, CSrc));
				}
				DataView dvGroupCol = null;
				if ("I1,I2".IndexOf(dt.Rows[0]["ScreenTypeName"].ToString()) >= 0)
				{
					using (GenScreensAccessBase dac = GetGenScreensAccess())
					{
                        dvGroupCol = new DataView(dac.GetObjGroupCol(screenId, CPrj, CSrc));
					}
				}
				DataTable dtLis = null;
				using (GenScreensAccessBase dac = GetGenScreensAccess())
				{
					if ("I1,I2".IndexOf(dt.Rows[0]["ScreenTypeName"].ToString()) >= 0)
					{
						dtLis = dac.GetScreenLisI1ById(screenId, dt.Rows[0]["ProgramName"].ToString() + screenId.ToString(), dt.Rows[0]["dbAppDatabase"].ToString(), dt.Rows[0]["dbDesDatabase"].ToString(), CPrj.TarDesDatabase, dt.Rows[0]["multiDesignDb"].ToString(), dt.Rows[0]["SysProgram"].ToString(), CSrc);
					}
					else	// Grid screen.
					{
						dtLis = dac.GetScreenLisI3ById(screenId, dt.Rows[0]["ProgramName"].ToString() + screenId.ToString(), dt.Rows[0]["dbAppDatabase"].ToString(), dt.Rows[0]["dbDesDatabase"].ToString(), CPrj.TarDesDatabase, dt.Rows[0]["multiDesignDb"].ToString(), dt.Rows[0]["SysProgram"].ToString(), CSrc);
					}
				}
				DataTable dtDtl = null;
				using (GenScreensAccessBase dac = GetGenScreensAccess())
				{
					if (dt.Rows[0]["ScreenTypeName"].ToString() == "I2")
					{
						dtDtl = dac.GetScreenLisI2ById(screenId, dt.Rows[0]["ProgramName"].ToString() + screenId.ToString(), dt.Rows[0]["dbAppDatabase"].ToString(), dt.Rows[0]["dbDesDatabase"].ToString(), CPrj.TarDesDatabase, dt.Rows[0]["multiDesignDb"].ToString(), dt.Rows[0]["SysProgram"].ToString(), CSrc);
					}
				}
                //DataView dvARule = null;
                //using (GenScreensAccessBase dac = GetGenScreensAccess())
                //{
                //    dvARule = new DataView(dac.GetAdvRule(screenId, CPrj, CSrc));
                //}
				DataView dvWRule = null;
				using (GenScreensAccessBase dac = GetGenScreensAccess())
				{
					dvWRule = new DataView(dac.GetWebRule(screenId, CPrj, CSrc));
				}
                
                // Generate or remove automated audit trail server rules:
                MkScrAudit(dt.Rows[0]["GenAudit"].ToString(), dt.Rows[0]["MultiDesignDb"].ToString(), screenId, dt.Rows[0]["ScreenTypeName"].ToString(), CSrc, dt.Rows[0]["dbAppDatabase"].ToString(), dt.Rows[0]["dbDesDatabase"].ToString());

                DataView dvSRule = null;
				using (GenScreensAccessBase dac = GetGenScreensAccess())
				{
					dvSRule = new DataView(dac.GetServerRule(screenId, CPrj, CSrc, null, null));
				}
                try
				{
                    // Make sure there is at least one default row in ScreenTab:
                    using (GenScreensAccessBase dac = GetGenScreensAccess())
                    {
                        dac.SetScrTab(CSrc);
                    }
                    // Create source rule tier programs before CreateProgW:
					//CreateProgR(dt.Rows[0], screenId, dv, dtLis, dtDtl, dvARule, dvSRule, dvCri, CPrj, CSrc, CPrj.SrcRuleProgramPath, CPrj.SrcRuleFrwork);
					// Create target rule tier programs:
                    //if (CPrj.SrcRuleProgramPath != CPrj.TarRuleProgramPath)
                    //{
                    //    CreateProgR(dt.Rows[0], screenId, dv, dtLis, dtDtl, dvARule, dvSRule, dvCri, CPrj, CSrc, CPrj.TarRuleProgramPath, CPrj.TarRuleFrwork);
                    //}
					// Create source Web Service tier programs:
					//CreateProgW(dt.Rows[0], screenId, dv, dtLis, dtDtl, dvARule, CPrj, CSrc);
					// Create source client tier programs (depend on the above web service programs):
                    CreateProgC(dt.Rows[0], screenId, screenTitle, dv, dvTab, dtLis, dtDtl, dvWRule, dvCri, dvGroupCol, CPrj, CSrc, CPrj.SrcClientProgramPath, CPrj.SrcClientFrwork);
                    // Create target client tier programs:
                    if (CPrj.SrcClientProgramPath != CPrj.TarClientProgramPath)
                    {
                        CreateProgC(dt.Rows[0], screenId, screenTitle, dv, dvTab, dtLis, dtDtl, dvWRule, dvCri, dvGroupCol, CPrj, CSrc, CPrj.TarClientProgramPath, CPrj.TarClientFrwork);
                    }
                    // No need to create source data tier programs because inline query has been used to take care of 2GB columns.
					//				using (GenScreensAccessBase dac = GetGenScreensAccess())
					//				{
					//					dac.MkScreenUpd(screenId, dt.Rows[0]["ScreenTypeName"].ToString(), dt.Rows[0]["ProgramName"].ToString() + screenId.ToString(), CSrc, dt.Rows[0]["dbAppDatabase"].ToString(), dt.Rows[0]["dbDesDatabase"].ToString(), CPrj.SrcDesDatabase, dt.Rows[0]["multiDesignDb"].ToString(), dt.Rows[0]["SysProgram"].ToString());
					//				}
                    // The following is needed for AdminSystem.UpdScrCriteria:
                    if (dt.Rows[0]["GenerateSr"].ToString() == "Y")
                    {
                        if (dvCri.Count > 0)
                        {
                            using (GenScreensAccessBase dac = GetGenScreensAccess())
                            {
                                dac.MkScreenUpdIn(screenId, dt.Rows[0]["ProgramName"].ToString() + screenId.ToString() + "In", CSrc, dt.Rows[0]["dbAppDatabase"].ToString(), dt.Rows[0]["dbDesDatabase"].ToString());
                            }
                            // generate all Ddl for criterias
                            using (AdminAccessBase dac = GetAdminAccess())
                            {
                                foreach (DataRowView drv in dvCri)
                                {
                                    if (drv["DisplayName"].ToString() == "ComboBox"
                                        || drv["DisplayName"].ToString() == "DropDownList"
                                        || drv["DisplayName"].ToString() == "ListBox"
                                        || drv["DisplayName"].ToString() == "RadioButtonList"
                                        )
                                    {
                                        dac.MkGetScreenIn(screenId.ToString(), drv["ScreenCriId"].ToString(), "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "C" + drv["ScreenCriId"].ToString(), dt.Rows[0]["dbAppDatabase"].ToString(), dt.Rows[0]["dbDesDatabase"].ToString(), drv["MultiDesignDb"].ToString(), CSrc.SrcConnectionString, CSrc.SrcDbPassword, true);
                                    }
                                }
                            }

                        }
                        // Create target data tier programs:
                        if (CTar.TarDbServer != CSrc.SrcDbServer && CPrj.SrcDesProviderCd == "M")
                        {
                            CreateProgD(dt.Rows[0], screenId, dbAppDatabase, dv, dvSRule, dvCri, CPrj, CSrc, CTar, dbConnectionString, dbPassword);
                        }
                    }
                    // Reset regen flag to No:
                    using (GenScreensAccessBase dac = GetGenScreensAccess())
                    {
                        dac.SetScrNeedRegen(screenId, CSrc);
                    }
                }
                catch (Exception e) { ApplicationAssert.CheckCondition(false, "", "", e.Message); return false; }
			}
			return true;
		}


        private void MkScrAudit(string Gen, string MultiDesignDb, Int32 ScreenId, string ScreenTypeName, CurrSrc CSrc, string AppDatabase, string DesDatabase)
        {
            using (GenScreensAccessBase dac = GetGenScreensAccess())
            {
                dac.MkScrAudit("D", ScreenId, "Y", Gen, MultiDesignDb, CSrc, AppDatabase, DesDatabase);
                dac.MkScrAudit("A", ScreenId, "Y", Gen, MultiDesignDb, CSrc, AppDatabase, DesDatabase);
                dac.MkScrAudit("U", ScreenId, "Y", Gen, MultiDesignDb, CSrc, AppDatabase, DesDatabase);
                if (ScreenTypeName == "I2")
                {
                    dac.MkScrAudit("D", ScreenId, "N", Gen, MultiDesignDb, CSrc, AppDatabase, DesDatabase);
                    dac.MkScrAudit("A", ScreenId, "N", Gen, MultiDesignDb, CSrc, AppDatabase, DesDatabase);
                    dac.MkScrAudit("U", ScreenId, "N", Gen, MultiDesignDb, CSrc, AppDatabase, DesDatabase);
                }
            }
        }

        //public void ProxyProgram(Int32 screenId, CurrPrj CPrj, CurrSrc CSrc)
        //{
        //    DataTable dt = null;
        //    using (GenScreensAccessBase dac = GetGenScreensAccess())
        //    {
        //        dt = dac.GetScreenById(screenId, CPrj, CSrc);
        //    }
        //    if (dt.Rows[0]["GenerateSc"].ToString() == "Y")
        //    {
        //        StreamWriter sw = new StreamWriter(CPrj.SrcRuleProgramPath + "Service" + CSrc.SrcSystemId.ToString() + "\\" + dt.Rows[0]["ProgramName"].ToString() + "Ws.cs");
        //        try { sw.Write(Robot.MkWsProxy(dt.Rows[0]["ProgramName"].ToString(), CPrj, CSrc)); }
        //        catch (Exception e) { ApplicationAssert.CheckCondition(false, "", "", e.Message); }
        //        finally { sw.Close(); }
        //        Robot.ModifyCsproj(false, CPrj.SrcRuleProgramPath + "Service" + CSrc.SrcSystemId.ToString() + "\\Service" + CSrc.SrcSystemId.ToString() + ".csproj", dt.Rows[0]["ProgramName"].ToString() + "Ws.cs", string.Empty, CPrj.SrcClientFrwork);
        //    }
        //}

        //private void CreateProgW(DataRow dw, Int32 screenId, DataView dv, DataTable dtLis, DataTable dtDtl, DataView dvARule, CurrPrj CPrj, CurrSrc CSrc)
        //{
        //    StreamWriter sw = new StreamWriter(CPrj.SrcWsProgramPath + dw["ProgramName"].ToString() + "Ws.asmx");
        //    try { sw.Write(MakeAsmx(dw, screenId, dv, dtLis, dtDtl, dvARule, dw["dbAppDatabase"].ToString(), dw["dbDesDatabase"].ToString(), CPrj, CSrc)); }
        //    finally { sw.Close(); }
        //}

		private void CreateProgC(DataRow dw, Int32 screenId, string screenTitle, DataView dv, DataView dvTab, DataTable dtLis, DataTable dtDtl, DataView dvWRule, DataView dvCri, DataView dvGroupCol, CurrPrj CPrj, CurrSrc CSrc, string clientProgramPath, string clientFrwork)
		{
            StringBuilder sbAspx = MakeAspx(dw, screenId, screenTitle, CPrj, clientFrwork);
            StringBuilder sbAspxCs = MakeAspxCs(dw, screenTitle, CPrj, clientFrwork);
            StringBuilder sbAscx = MakeAscx(dw, screenId, screenTitle, dv, dvTab, dvCri, dvGroupCol, CPrj, CSrc, clientFrwork);
            StringBuilder sbAscxCs = MakeAscxCs(dw, screenId, screenTitle, dv, dvTab, dtLis, dtDtl, dvWRule, dvCri, dvGroupCol, dw["dbAppDatabase"].ToString(), dw["dbDesDatabase"].ToString(), CPrj, CSrc, clientFrwork);
            // normalize expected value
            clientProgramPath = clientProgramPath.EndsWith("\\") || clientProgramPath.EndsWith("/") ? clientProgramPath : clientProgramPath + "\\";
            if (dw["GenerateSc"].ToString() == "Y")
            {
                //StreamWriter sw = new StreamWriter(clientProgramPath + dw["ProgramName"].ToString() + ".aspx",false,System.Text.Encoding.UTF8);
                StreamWriter sw = new StreamWriter(clientProgramPath + dw["ProgramName"].ToString() + ".aspx");
                try { sw.Write(sbAspx); }
                finally { sw.Close(); }
			    sw = new StreamWriter(clientProgramPath + dw["ProgramName"].ToString() + ".aspx.cs");
			    try {sw.Write(sbAspxCs);} finally {sw.Close();}
			    sw = new StreamWriter(clientProgramPath + @"modules\" + dw["ProgramName"].ToString() + "Module.ascx");
			    try {sw.Write(sbAscx);} finally {sw.Close();}
                sw = new StreamWriter(clientProgramPath + @"modules\" + dw["ProgramName"].ToString() + "Module.ascx.cs");
                try { sw.Write(sbAscxCs); } finally { sw.Close(); }
            }
		}

		//private void CreateProgR(DataRow dw, Int32 screenId, DataView dv, DataTable dtLis, DataTable dtDtl, DataView dvARule, DataView dvSRule, DataView dvCri, CurrPrj CPrj, CurrSrc CSrc, string ruleProgramPath, string ruleFrwork)
		//{
            //StreamWriter sw = null;
            //sw = new StreamWriter(ruleProgramPath + "Facade" + CSrc.SrcSystemId.ToString() + "\\" + dw["ProgramName"].ToString() + "System.cs");
            //try { sw.Write(MakeSystemCs(dw, screenId, dv, dtLis, dtDtl, dvARule, dw["dbAppDatabase"].ToString(), dw["dbDesDatabase"].ToString(), CPrj, CSrc)); }
            //finally { sw.Close(); }
            //Robot.ModifyCsproj(false, ruleProgramPath + "Facade" + CSrc.SrcSystemId.ToString() + "\\Facade" + CSrc.SrcSystemId.ToString() + ".csproj", dw["ProgramName"].ToString() + "System.cs", string.Empty, ruleFrwork);
            //sw = new StreamWriter(ruleProgramPath + "Rule" + CSrc.SrcSystemId.ToString() + "\\" + dw["ProgramName"].ToString() + "Rules.cs");
            //try {sw.Write(MakeRulesCs(dw, screenId, dv, dtLis, dtDtl, dvARule, CPrj, CSrc));} finally {sw.Close();}
            //Robot.ModifyCsproj(false, ruleProgramPath + "Rule" + CSrc.SrcSystemId.ToString() + "\\Rule" + CSrc.SrcSystemId.ToString() + ".csproj", dw["ProgramName"].ToString() + "Rules.cs", string.Empty, ruleFrwork);
            //sw = new StreamWriter(ruleProgramPath + "Access" + CSrc.SrcSystemId.ToString() + "\\" + dw["ProgramName"].ToString() + "Access.cs");
            //try {sw.Write(MakeAccessCs(dw, screenId, dv, dtLis, dtDtl, dvARule, dvSRule, dvCri, dw["dbAppDatabase"].ToString(), dw["dbDesDatabase"].ToString(), CPrj, CSrc));} finally {sw.Close();}
            //Robot.ModifyCsproj(false, ruleProgramPath + "Access" + CSrc.SrcSystemId.ToString() + "\\Access" + CSrc.SrcSystemId.ToString() + ".csproj", dw["ProgramName"].ToString() + "Access.cs", string.Empty, ruleFrwork);
            //sw = new StreamWriter(ruleProgramPath + "Common" + CSrc.SrcSystemId.ToString() + "\\Data\\" + dw["ProgramName"].ToString() + screenId.ToString() + ".cs");
            //try {sw.Write(MakeDataCs(dw, screenId, dv, CPrj, CSrc));} finally {sw.Close();}
            //Robot.ModifyCsproj(false, ruleProgramPath + "Common" + CSrc.SrcSystemId.ToString() + "\\Common" + CSrc.SrcSystemId.ToString() + ".csproj", @"Data\" + dw["ProgramName"].ToString() + screenId.ToString() + ".cs", string.Empty, ruleFrwork);
            //if (dvCri.Count > 0)
            //{
            //    sw = new StreamWriter(ruleProgramPath + "Common" + CSrc.SrcSystemId.ToString() + "\\Data\\" + dw["ProgramName"].ToString() + screenId.ToString() + "In.cs");
            //    try {sw.Write(MakeDataInCs(dw, screenId, dvCri, CPrj, CSrc));} finally {sw.Close();}
            //    Robot.ModifyCsproj(false, ruleProgramPath + "Common" + CSrc.SrcSystemId.ToString() + "\\Common" + CSrc.SrcSystemId.ToString() + ".csproj", @"Data\" + dw["ProgramName"].ToString() + screenId.ToString() + "In.cs", string.Empty, ruleFrwork);
            //}
		//}

		public void CreateProgD(DataRow dw, Int32 screenId, string dbAppDatabase, DataView dv, DataView dvSRule, DataView dvCri, CurrPrj CPrj, CurrSrc CSrc, CurrTar CTar, string dbConnectionString, string dbPassword)
		{
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
                if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || ",document,upload,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0))
				{
					PortProg(dbAppDatabase, "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString(), "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
				}
			}
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				PortProg(dbAppDatabase, "GetExp" + dw["ProgramName"].ToString() + screenId.ToString(), "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
				PortProg(dbAppDatabase, "Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById", "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					PortProg(dbAppDatabase, "Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById", "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
				}
			}
			foreach (DataRowView drv in dvSRule)
			{
				PortProg(dbAppDatabase, drv["ProcedureName"].ToString(), "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
			}
			PortProg(dbAppDatabase, "GetLis" + dw["ProgramName"].ToString() + screenId.ToString(), "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
//			PortProg(dbAppDatabase, "Add" + dw["ProgramName"].ToString() + screenId.ToString(), "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
//			PortProg(dbAppDatabase, "Del" + dw["ProgramName"].ToString() + screenId.ToString(), "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
//			PortProg(dbAppDatabase, "Upd" + dw["ProgramName"].ToString() + screenId.ToString(), "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
//			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
//			{
//				PortProg(dbAppDatabase, "Add" + dw["ProgramName"].ToString() + screenId.ToString() + "Dt", "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
//				PortProg(dbAppDatabase, "Del" + dw["ProgramName"].ToString() + screenId.ToString() + "Dt", "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
//				PortProg(dbAppDatabase, "Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "Dt", "P", CPrj, CSrc, CTar, dbConnectionString, dbPassword);
//			}
		}

		private void PortProg(string dbAppDatabase, string SpName, string SpType, CurrPrj CPrj, CurrSrc CSrc, CurrTar CTar, string dbConnectionString, string dbPassword)
		{
			string db = CSrc.SrcDbDatabase;		// Save for later restore.
			CSrc.SrcDbDatabase = dbAppDatabase; CTar.TarDbDatabase = dbAppDatabase;
			DbScript ds = new DbScript(string.Empty, false);
			DbPorting pt = new DbPorting();
			string ss = ds.ScriptCreaSp(SpName, SpType, CPrj.SrcDesProviderCd, true, CSrc, CTar);
			if (ss != string.Empty)
			{
				if (CPrj.TarDesProviderCd == "S") {ss = pt.SqlToSybase (CPrj.EntityId,CPrj.TarDesDatabase,ss,dbConnectionString,dbPassword);}
				using (RobotAccessBase dac = GetRobotAccess())
				{
					dac.ExecSql(ds.ScriptDropSp(SpName, SpType), CTar.TarConnectionString, CTar.TarDbPassword);
				}
				using (RobotAccessBase dac = GetRobotAccess())
				{
					dac.ExecSql("SET QUOTED_IDENTIFIER ON", CTar.TarConnectionString, CTar.TarDbPassword);
				}
				using (RobotAccessBase dac = GetRobotAccess())
				{
					if (CPrj.TarDesProviderCd == "S")
					{
						dac.ExecSql("SET ANSINULL ON", CTar.TarConnectionString, CTar.TarDbPassword);
					}
					else
					{
						dac.ExecSql("SET ANSI_NULLS ON", CTar.TarConnectionString, CTar.TarDbPassword);
					}
				}
				using (RobotAccessBase dac = GetRobotAccess())
				{
					dac.ExecSql(ss, CTar.TarConnectionString, CTar.TarDbPassword);
				}
				using (RobotAccessBase dac = GetRobotAccess())
				{
					dac.ExecSql("SET QUOTED_IDENTIFIER OFF", CTar.TarConnectionString, CTar.TarDbPassword);
				}
			}
			CSrc.SrcDbDatabase = db; CTar.TarDbDatabase = db;
		}

        //private StringBuilder MakeAsmx(DataRow dw, Int32 screenId, DataView dv, DataTable dtLis, DataTable dtDtl, DataView dvARule, string appDatabase, string sysDatabase, CurrPrj CPrj, CurrSrc CSrc)
        //{
        //    string pMKey = string.Empty;
        //    //bool firstWord = true;
        //    bool bRemove = false;
        //    //DataTable dt = null;
        //    StringBuilder parameterNames = new StringBuilder();
        //    StringBuilder parameterTypes = new StringBuilder();
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("<%@ WebService language=\"c#\" Class=\"" + dw["ProgramName"].ToString() + "Ws\" %>" + Environment.NewLine);
        //    sb.Append("using System;" + Environment.NewLine);
        //    sb.Append("using System.Data;" + Environment.NewLine);
        //    sb.Append("using System.Web;" + Environment.NewLine);
        //    sb.Append("using System.Web.Services;" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Facade" + CSrc.SrcSystemId.ToString() + ";" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ";" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ".Data;" + Environment.NewLine);
        //    if (CSrc.SrcSystemId != 3)	// Admin.
        //    {
        //        sb.Append("using RO.Facade3;" + Environment.NewLine);
        //        sb.Append("using RO.Common3;" + Environment.NewLine);
        //        sb.Append("using RO.Common3.Data;" + Environment.NewLine);
        //    }
        //    sb.Append(Environment.NewLine);
        //    sb.Append("[WebService(Namespace = \"http://Rintagi.com/\")]" + Environment.NewLine);
        //    sb.Append("[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]" + Environment.NewLine);
        //    sb.Append("public partial class " + dw["ProgramName"].ToString() + "Ws: WebService" + Environment.NewLine);
        //    sb.Append("{" + Environment.NewLine);
        //    dv.RowFilter = string.Empty;
        //    foreach (DataRowView drv in dv)
        //    {
        //        if (drv["MasterTable"].ToString() == "Y" && drv["PrimaryKey"].ToString() == "Y")
        //        {
        //            pMKey = drv["ColumnName"].ToString(); break;
        //        }
        //    }
        //    foreach (DataRowView drv in dv)
        //    {
        //        if (drv["DisplayMode"].ToString().ToLower() == "document")
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("	[WebMethod]" + Environment.NewLine);
        //            sb.Append("	public string Del" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(string MasterId, string DocId, string UsrId, string dbConnectionString, string dbPassword)" + Environment.NewLine);
        //            sb.Append("	{" + Environment.NewLine);
        //            sb.Append("		return (new " + dw["ProgramName"].ToString() + "System()).Del" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(MasterId, DocId, UsrId, dbConnectionString, dbPassword);" + Environment.NewLine);
        //            sb.Append("	}" + Environment.NewLine);
        //        }
        //        //if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
        //        //{
        //        //    using (GenScreensAccessBase dac = GetGenScreensAccess())
        //        //    {
        //        //        dt = dac.GetScreenObjDdlById(screenId, Int32.Parse(drv["ScreenObjId"].ToString()), "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString(), "N", appDatabase, sysDatabase, CPrj.SrcDesDatabase, pMKey, drv["MultiDesignDb"].ToString(), CSrc);
        //        //    }
        //        //    bRemove = false;
        //        //    dvARule.RowFilter = "RuleLayerCd = 'W' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        //    foreach (DataRowView dra in dvARule)
        //        //    {
        //        //        if (dra["RmFuncProc"].ToString() == "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString()) { bRemove = true; break; }
        //        //    }
        //        //    if (!bRemove)
        //        //    {
        //        //        sb.Append(Environment.NewLine);
        //        //        sb.Append("	[WebMethod]" + Environment.NewLine);
        //        //        sb.Append("	public string GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "(Int32 screenId, bool bAll, int topN, ");
        //        //        parameterNames.Remove(0, parameterNames.Length);
        //        //        parameterTypes.Remove(0, parameterTypes.Length);
        //        //        parameterNames.Append(dt.Rows[0]["parameter2Names"].ToString());
        //        //        parameterTypes.Append(dt.Rows[0]["parameter2Types"].ToString());
        //        //        firstWord = true;
        //        //        while (parameterNames.Length > 0 && parameterTypes.Length > 0)
        //        //        {
        //        //            if (firstWord) { firstWord = false; } else { sb.Append(", "); }
        //        //            sb.Append(Utils.PopFirstWord(parameterTypes, (char)44) + " " + Utils.PopFirstWord(parameterNames, (char)44));
        //        //        }
        //        //        sb.Append(Robot.GetCnDclr(drv["MultiDesignDb"].ToString(), "N") + ",string filterTxt, string ui, string uc)" + Environment.NewLine);
        //        //        sb.Append("	{" + Environment.NewLine);
        //        //        sb.Append("		return XmlUtils.DataTableToXml((new " + dw["ProgramName"].ToString() + "System()).GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "(screenId,bAll,topN," + dt.Rows[0]["parameter2Names"].ToString() + Robot.GetCnParm(drv["MultiDesignDb"].ToString(), "N") + ",filterTxt,ui.XmlToObject<UsrImpr>(),uc.XmlToObject<UsrCurr>()));" + Environment.NewLine);
        //        //        sb.Append("	}" + Environment.NewLine);
        //        //    }
        //        //}
        //    }
        //    //if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'W' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "GetExp" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("	[WebMethod]" + Environment.NewLine);
        //    //        sb.Append("	public string GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "(string useGlobalFilter, Int32 screenId");
        //    //        sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ", Int32 screenFilterId, string dvCri, string ui, string uc, string ds)" + Environment.NewLine);
        //    //        sb.Append("	{" + Environment.NewLine);
        //    //        sb.Append("		return XmlUtils.DataTableToXml((new " + dw["ProgramName"].ToString() + "System()).GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "(useGlobalFilter,screenId" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",screenFilterId,XmlUtils.XmlToDataView(dvCri),ui.XmlToObject<UsrImpr>(),uc.XmlToObject<UsrCurr>(),XmlUtils.XmlToDataSet(ds)));" + Environment.NewLine);
        //    //        sb.Append("	}" + Environment.NewLine);
        //    //    }
        //    //}
        //    //bRemove = false;
        //    //dvARule.RowFilter = "RuleLayerCd = 'W' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //foreach (DataRowView dra in dvARule)
        //    //{
        //    //    if (dra["RmFuncProc"].ToString() == "GetLis" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    //}
        //    //if (!bRemove)
        //    //{
        //    //    sb.Append(Environment.NewLine);
        //    //    sb.Append("	[WebMethod]" + Environment.NewLine);
        //    //    sb.Append("	public string GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "(string useGlobalFilter, Int32 screenId, int topN ");
        //    //    sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ", Int32 screenFilterId, string key, string filterTxt, string dvCri, string ui, string uc, string ds)" + Environment.NewLine);
        //    //    sb.Append("	{" + Environment.NewLine);
        //    //    sb.Append("		return XmlUtils.DataTableToXml((new " + dw["ProgramName"].ToString() + "System()).GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "(useGlobalFilter,screenId,topN" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",screenFilterId,key,filterTxt,XmlUtils.XmlToDataView(dvCri),ui.XmlToObject<UsrImpr>(),uc.XmlToObject<UsrCurr>(),XmlUtils.XmlToDataSet(ds)));" + Environment.NewLine);
        //    //    sb.Append("	}" + Environment.NewLine);
        //    //}
        //    //if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'W' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById") { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("	[WebMethod]" + Environment.NewLine);
        //    //        sb.Append("	public string Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById(");
        //    //        parameterNames.Remove(0, parameterNames.Length);
        //    //        parameterNames.Append(dtLis.Rows[0]["parameter2Names"].ToString());
        //    //        firstWord = true;
        //    //        while (parameterNames.Length > 0)
        //    //        {
        //    //            if (firstWord) { firstWord = false; } else { sb.Append(", "); }
        //    //            sb.Append("string " + Utils.PopFirstWord(parameterNames, (char)44));
        //    //        }
        //    //        sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //    //        sb.Append("	{" + Environment.NewLine);
        //    //        sb.Append("		return XmlUtils.DataTableToXml((new " + dw["ProgramName"].ToString() + "System()).Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById(" + dtLis.Rows[0]["parameter2Names"].ToString() + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + "));" + Environment.NewLine);
        //    //        sb.Append("	}" + Environment.NewLine);
        //    //    }
        //    //}
        //    //if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'W' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById") { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("	[WebMethod]" + Environment.NewLine);
        //    //        sb.Append("	public string Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById(Int32 screenId, ");
        //    //        parameterNames.Remove(0, parameterNames.Length);
        //    //        parameterNames.Append(dtDtl.Rows[0]["parameter2Names"].ToString());
        //    //        firstWord = true;
        //    //        while (parameterNames.Length > 0)
        //    //        {
        //    //            if (firstWord) { firstWord = false; } else { sb.Append(", "); }
        //    //            sb.Append("string " + Utils.PopFirstWord(parameterNames, (char)44));
        //    //        }
        //    //        sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ", Int32 screenFilterId, string ui, string uc)" + Environment.NewLine);
        //    //        sb.Append("	{" + Environment.NewLine);
        //    //        sb.Append("		return XmlUtils.DataTableToXml((new " + dw["ProgramName"].ToString() + "System()).Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById(screenId," + dtDtl.Rows[0]["parameter2Names"].ToString() + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",screenFilterId,ui.XmlToObject<UsrImpr>(),uc.XmlToObject<UsrCurr>()));" + Environment.NewLine);
        //    //        sb.Append("	}" + Environment.NewLine);
        //    //    }
        //    //}
        //    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    {
        //        bRemove = false;
        //        dvARule.RowFilter = "RuleLayerCd = 'W' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Add" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //        }
        //        if (!bRemove)
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("	[WebMethod]" + Environment.NewLine);
        //            sb.Append("	public string Add" + dw["ProgramName"].ToString() + screenId.ToString() + "(string lu, string ui, string uc, string ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //            sb.Append("	{" + Environment.NewLine);
        //            sb.Append("		return (new " + dw["ProgramName"].ToString() + "System()).Add" + dw["ProgramName"].ToString() + screenId.ToString() + "(lu.XmlToObject<LoginUsr>(),ui.XmlToObject<UsrImpr>(),uc.XmlToObject<UsrCurr>(),ds.XmlToDataSet<" + dw["ProgramName"].ToString() + screenId.ToString() + ">()" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //            sb.Append("	}" + Environment.NewLine);
        //        }
        //        bRemove = false;
        //        dvARule.RowFilter = "RuleLayerCd = 'W' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Del" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //        }
        //        if (!bRemove)
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("	[WebMethod]" + Environment.NewLine);
        //            sb.Append("	public bool Del" + dw["ProgramName"].ToString() + screenId.ToString() + "(string lu, string ui, string uc, string ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //            sb.Append("	{" + Environment.NewLine);
        //            sb.Append("		return (new " + dw["ProgramName"].ToString() + "System()).Del" + dw["ProgramName"].ToString() + screenId.ToString() + "(lu.XmlToObject<LoginUsr>(),ui.XmlToObject<UsrImpr>(),uc.XmlToObject<UsrCurr>(),ds.XmlToDataSet<" + dw["ProgramName"].ToString() + screenId.ToString() + ">()" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //            sb.Append("	}" + Environment.NewLine);
        //        }
        //    }
        //    bRemove = false;
        //    dvARule.RowFilter = "RuleLayerCd = 'W' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    foreach (DataRowView dra in dvARule)
        //    {
        //        if (dra["RmFuncProc"].ToString() == "Upd" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    }
        //    if (!bRemove)
        //    {
        //        sb.Append(Environment.NewLine);
        //        sb.Append("	[WebMethod]" + Environment.NewLine);
        //        sb.Append("	public bool Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "(string lu, string ui, string uc, string ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //        sb.Append("	{" + Environment.NewLine);
        //        sb.Append("		return (new " + dw["ProgramName"].ToString() + "System()).Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "(lu.XmlToObject<LoginUsr>(),ui.XmlToObject<UsrImpr>(),uc.XmlToObject<UsrCurr>(),ds.XmlToDataSet<" + dw["ProgramName"].ToString() + screenId.ToString() + ">()" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //        sb.Append("	}" + Environment.NewLine);
        //    }
        //    dvARule.RowFilter = "RuleLayerCd = 'W'";
        //    foreach (DataRowView dra in dvARule)
        //    {
        //        sb.Append(Environment.NewLine);
        //        sb.Append("	//AdvRule: " + dra["RuleName"].ToString() + Environment.NewLine);
        //        sb.Append("	" + dra["AdvRuleProg"].ToString() + Environment.NewLine);
        //        sb.Append("	// *** AdvRule End *** //" + Environment.NewLine);
        //    }
        //    sb.Append("}" + Environment.NewLine);
        //    return sb;
        //}

        private StringBuilder MakeAspx(DataRow dw, Int32 screenId, string screenTitle, CurrPrj CPrj, string clientFrwork)
		{
			StringBuilder sb = new StringBuilder();
            sb.Append("<%@ Page language=\"c#\" MasterPageFile=\"Default.master\" EnableEventValidation=\"false\"");
            if (dw["ValidateReq"].ToString() == "N") { sb.Append(" ValidateRequest=\"false\""); }  // In .Net4 add "<httpRuntime requestValidationMode="2.0"/>" to Web.config?
            //sb.Append(" Inherits=\"" + CPrj.EntityCode + ".Web." + dw["ProgramName"].ToString() + "\" CodeFile=\"" + dw["ProgramName"].ToString() + ".aspx.cs\" Title=\"" + Config.WebTitle + " - " + screenTitle + "\" %>" + Environment.NewLine);
            sb.Append(" Inherits=\"" + CPrj.EntityCode + ".Web." + dw["ProgramName"].ToString() + "\" CodeFile=\"" + dw["ProgramName"].ToString() + ".aspx.cs\" %>" + Environment.NewLine);
            sb.Append("<%@ Register TagPrefix=\"Module\" TagName=\"" + dw["ProgramName"].ToString() + "\" Src=\"modules/" + dw["ProgramName"].ToString() + "Module.ascx\" %>" + Environment.NewLine);
            sb.Append("<asp:Content ContentPlaceHolderID=\"MHR\" Runat=\"Server\"><Module:" + dw["ProgramName"].ToString() + " id=\"M" + screenId.ToString() + "\" runat=\"server\" /></asp:Content>" + Environment.NewLine);
			return sb;
		}

		private StringBuilder MakeAspxCs(DataRow dw, string screenTitle, CurrPrj CPrj, string clientFrwork)
		{
            StringBuilder sb = new StringBuilder();
			sb.Append("using System;" + Environment.NewLine);
			sb.Append("using System.Collections;" + Environment.NewLine);
			sb.Append("using System.ComponentModel;" + Environment.NewLine);
			sb.Append("using System.Data;" + Environment.NewLine);
			sb.Append("using System.Drawing;" + Environment.NewLine);
			sb.Append("using System.Web;" + Environment.NewLine);
			sb.Append("using System.Web.SessionState;" + Environment.NewLine);
			sb.Append("using System.Web.UI;" + Environment.NewLine);
			sb.Append("using System.Web.UI.WebControls;" + Environment.NewLine);
			sb.Append("using System.Web.UI.HtmlControls;" + Environment.NewLine);
            sb.Append("using RO.Common3;" + Environment.NewLine);
            sb.Append(Environment.NewLine);
			sb.Append("namespace " + CPrj.EntityCode + ".Web" + Environment.NewLine);
			sb.Append("{" + Environment.NewLine);
			sb.Append("	public partial class " + dw["ProgramName"].ToString() + " : RO.Web.PageBase" + Environment.NewLine);
			sb.Append("	{" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		public " + dw["ProgramName"].ToString() + "()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
            sb.Append("			Page.PreInit += new System.EventHandler(Page_PreInit);" + Environment.NewLine);
            sb.Append("			Page.Init += new System.EventHandler(Page_Init);" + Environment.NewLine);
            sb.Append("			Page.Title = Config.WebTitle + \" - " + screenTitle + "\";" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		protected void Page_Load(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		protected void Page_PreInit(object sender, EventArgs e)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			SetMasterPage();" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append("		protected void Page_Init(object sender, EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			InitializeComponent();" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		#region Web Form Designer generated code" + Environment.NewLine);
			sb.Append("		/// <summary>" + Environment.NewLine);
			sb.Append("		/// Required method for Designer support - do not modify" + Environment.NewLine);
			sb.Append("		/// the contents of this method with the code editor." + Environment.NewLine);
			sb.Append("		/// </summary>" + Environment.NewLine);
			sb.Append("		private void InitializeComponent()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append("		#endregion" + Environment.NewLine);
			sb.Append("	}" + Environment.NewLine);
			sb.Append("}" + Environment.NewLine);
			return sb;
		}

        // No need for the expand icon if the box is big enough.
		private bool PopTextBox(DataRowView drv)
		{
			if (drv["DisplayMode"].ToString() == "MultiLine" && (drv["ColumnSize"].ToString() == string.Empty || int.Parse(drv["ColumnSize"].ToString()) <= 500 || drv["ColumnHeight"].ToString() == string.Empty || int.Parse(drv["ColumnHeight"].ToString()) <= 200))
			{
				return true;
			}
			else { return false; }
		}

        private StringBuilder MkEditInsr(DataRowView drv, StringBuilder sb, int iOffset, int ii, string pDKeyColumn, bool bEdit)
        {
            sb.Append("<div class='GrdInner" + (drv["ContentCss"].ToString().StartsWith(".") ? " " + drv["ContentCss"].ToString().Substring(1) : string.Empty));
            sb.Append("' style='");
            if (!string.IsNullOrEmpty(drv["ColumnSize"].ToString()) && !(drv["DisplayMode"].ToString().ToLower() == "imagebutton" && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary"))
            {
                sb.Append("max-width:" + drv["ColumnSize"].ToString() + "px;");
            }
            sb.Append(AlignmentTranslate(drv["ColumnJustify"].ToString()) + "' visible=\"<%# GridColumnVisible(" + (iOffset + ii).ToString() + ") %>\" runat=\"server\">");
            sb.Append("<div class=\"GrdEdtLabelText\"><asp:label id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "ml\" runat=\"server\" /></div>" + Environment.NewLine);
            if (drv["DisplayMode"].ToString().ToLower() == "upload")
            {
                sb.Append("		<table cellspacing=\"0\" cellpadding=\"0\"><tr>" + Environment.NewLine);
                sb.Append("		    <td><asp:Panel id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pan\" CssClass=\"DocPanel\" Visible=\"false\" runat=\"server\">" + Environment.NewLine);
                sb.Append("		    <table width=\"100%\"><tr>" + Environment.NewLine);
                sb.Append("		    <td style=\"display:none;\" ><asp:Button id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Upl\" CssClass=\"small blue button DocUpload\" OnClientClick=\"GridUpload(); return false;\" text=\"Upload\" runat=\"server\" /></td>" + Environment.NewLine);
                sb.Append("		    <td><asp:FileUpload id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Fi\" runat=\"server\"  onchange=\"AutoUpload(this,event);\" /></td>" + Environment.NewLine);
                sb.Append("		    </tr></table>" + Environment.NewLine);
                sb.Append("		    </asp:Panel>" + Environment.NewLine);
                sb.Append("		    <asp:TextBox id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" CssClass=\"GrdTxt\" MaxLength=\"100\"");
                if (bEdit) { sb.Append(" Text='<%# " + Robot.DataTypeConvert("Zf", drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), true) + "DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString()" + Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), string.Empty, false) + " %>'"); }
                sb.Append(" AutoPostBack=\"true\"");
                if ((drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y") && drv["ColumnIdentity"].ToString() != "Y")
                {
                    sb.Append(" OnTextChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged\"");
                }
                sb.Append(" runat=\"server\" /></td><td><asp:imagebutton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo\" OnClientClick='NoConfirm()' onclick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo_Click\" runat=\"server\" ImageUrl=\"~/Images/UpLoad.png\" CausesValidation=\"true\" /></td>" + Environment.NewLine);
                sb.Append("		</tr></table>" + Environment.NewLine);
            }
            else if (drv["DisplayMode"].ToString().ToLower() == "imagebutton")  // Check "drv["DdlRefColumnId"].ToString() == string.Empty" later.
            {
                if (drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                {
                    sb.Append("		<div class=\"DocPanel\"><table cellspacing=\"0\" cellpadding=\"0\"><tr>" + Environment.NewLine);
                    sb.Append("		    <td><asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"");
                    sb.Append(" ImageUrl='<%# DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\") as byte[] !=null ? RO.Common3.Utils.BlobPlaceHolder((DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\") as byte[])??(new byte[1]),true) : \"~/images/DefaultImg.png\" %>'");
                    sb.Append(" style=\"");
                    if (drv["ColumnSize"].ToString() != string.Empty) { sb.Append("max-width:" + drv["ColumnSize"].ToString() + "px;"); }
                    if (drv["ColumnHeight"].ToString() != string.Empty) { sb.Append("max-height:" + drv["ColumnHeight"].ToString() + "px;"); }
                    sb.Append("\"");
                    sb.Append(" runat=\"server\" /></td>" + Environment.NewLine);
                    if (drv["DdlRefColumnId"].ToString() == string.Empty)
                    {
                        //sb.Append("		    <td><asp:Button id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Upl\" CssClass=\"small blue button\" OnClientClick=\"GridUpload(); return false;\" text=\"Upload\" runat=\"server\" /></td>" + Environment.NewLine);
                        sb.Append("		    <td><asp:FileUpload id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Fi\" runat=\"server\" /></td>" + Environment.NewLine);
                        sb.Append("		    <td><asp:ImageButton ImageUrl=\"~/images/Btrash.gif\" ID=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Del\" OnClientClick=\"if (ConfirmPrompt(this,'Are you sure?')) NoConfirm(); else return false;\" runat=\"server\"/></td>" + Environment.NewLine);
                    }
                    sb.Append("		</tr></table></div>" + Environment.NewLine);
                }
                else if (string.IsNullOrEmpty(drv["ColumnId"].ToString()))
                {
                    sb.Append("		    <asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"");
                    if (drv["DefaultValue"].ToString() == string.Empty)
                    {
                        sb.Append(" ImageUrl=\"\" visible=\"false\" runat=\"server\"/>" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append(" ImageUrl=\"" + Utils.AddTilde(drv["DefaultValue"].ToString()) + "\" visible=\"true\" runat=\"server\"/>" + Environment.NewLine);
                    }
                }
                else
                {
                    sb.Append("		    <asp:TextBox id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"");
                    sb.Append(" CssClass=\"GrdTxt\"");
                    if (bEdit) { sb.Append(" Text='<%# " + Robot.DataTypeConvert("Zf", drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), true) + "DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString()" + Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), string.Empty, false) + " %>'"); }
                    sb.Append(" MaxLength=\"" + drv["ColumnLength"].ToString() + "\"");
                    sb.Append(" runat=\"server\" />" + Environment.NewLine);
                }
            }
            else
            {
                if (PopTextBox(drv) || (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload"))
                {
                    sb.Append("		<table cellspacing=\"0\" cellpadding=\"0\"><tr><td>" + Environment.NewLine);
                }
                sb.Append("		    ");
                if (drv["DisplayName"].ToString() == "ComboBox") { sb.Append("<rcasp:ComboBox autocomplete=\"off\""); }
                else if (",Button,HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 && !string.IsNullOrEmpty(drv["ColumnId"].ToString())) { sb.Append("<asp:TextBox"); }
                else if (drv["DisplayName"].ToString() == "Button") { sb.Append("<asp:Button"); }
                else if (drv["DisplayMode"].ToString() == "EncryptedTextBox") { sb.Append("<rcasp:EncryptedTextBox"); }
                else if (drv["DisplayMode"].ToString() == "OTPTextBox") { sb.Append("<rcasp:OTPTextBox"); }
                else { sb.Append("<asp:" + drv["DisplayName"].ToString()); }
                if (",Password,MultiLine,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0) { sb.Append(" TextMode=\"" + drv["DisplayMode"].ToString() + "\" autocomplete=\"new-password\""); }
                sb.Append(" id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"");
                if (",Button,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString()))
                {
                    sb.Append(" CssClass=\"");
                    if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("GrdDdl"); }
                    else if (drv["DisplayName"].ToString() == "CheckBox") { sb.Append("GrdBox"); }
                    else if (drv["ColumnJustify"].ToString() == "L") { sb.Append("GrdTxt"); }
                    else if (drv["ColumnJustify"].ToString() == "R") { sb.Append("GrdNum"); }
                    else { sb.Append("GrdCtr"); }
                    if (drv["DisplayName"].ToString() == "HyperLink") { sb.Append(" GrdLnk"); }
                    sb.Append("\"");
                }
                else if (drv["DisplayName"].ToString() == "Button") { sb.Append(" CssClass=\"small blue button\""); }
                if ((drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y") && drv["ColumnIdentity"].ToString() != "Y" && ",CheckBox,Calendar,TextBox,ComboBox,DropDownList,ListBox,RadioButtonList,Button,ImageButton,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                {
                    if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        //if (",RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append(" RepeatDirection=\"Horizontal\""); }
                        sb.Append(" AutoPostBack=\"true\" OnSelectedIndexChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectedIndexChanged\"");
                        if (drv["DisplayName"].ToString() == "ComboBox")
                        {
                            sb.Append(" OnTextChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged\" OnDDFindClick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_DDFindClick\"");
                        }
                    }
                    else if (",CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        sb.Append(" AutoPostBack=\"true\" OnCheckedChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_CheckedChanged\"");
                    }
                    else if (",Calendar,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        sb.Append(" OnSelectionChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectionChanged\"");
                    }
                    else if (",Button,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        // AutoPostBack not available for Button and ImageButton:
                        sb.Append(" OnClick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click\"");
                        // must check read only on data bind
                        sb.Append(" Enabled=\"<%# GridColumnEnable(" + (iOffset + ii).ToString() + ") %>\"");
                        sb.Append(" CommandArgument='<%# DataBinder.Eval(Container.DataItem,\"" + pDKeyColumn + "\").ToString() %>'");
                    }
                    else
                    {
                        sb.Append(" AutoPostBack=\"true\" OnTextChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged\"");
                    }
                }
                if (drv["ColumnHeight"].ToString() != string.Empty && drv["DisplayMode"].ToString().ToLower() != "starrating" && (",Button,ImageButton,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || string.IsNullOrEmpty(drv["ColumnId"].ToString()))) { sb.Append(" height=\"" + drv["ColumnHeight"].ToString() + "px\""); }
                if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                {
                    sb.Append(" DataValueField=\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" DataTextField=\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"");
                }
                else if (",TextBox,HyperLink,Button,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                {
                    if (drv["DisplayMode"].ToString().ToLower() == "currency")
                    {
                        if (bEdit)
                        {
                            sb.Append(" Text='<%# base.fxCurrency(DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString()");
                            sb.Append(string.IsNullOrEmpty(drv["DdlKeyColumnName"].ToString()) ? ",base.LUser.Culture" : ",DataBinder.Eval(Container.DataItem,\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "\").ToString()");
                            sb.Append(string.IsNullOrEmpty(drv["DdlRefColumnName"].ToString()) ? ",base.LUser.Culture)" : ",DataBinder.Eval(Container.DataItem,\"" + drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString() + "\").ToString())");
                            sb.Append(" %>'");
                        }
                    }
                    else if (drv["DisplayMode"].ToString().ToLower() == "encryptedtextbox")
                    {
                        if (bEdit) { sb.Append(" Text='<%# " + "fxEncryptedText(" + "DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString()" + ")" + " %>'"); }
                        if (drv["DataTypeSqlName"].ToString().IndexOf("Char") >= 0 && drv["DisplayMode"].ToString() != "MultiLine" && drv["ColumnLength"].ToString() != string.Empty && drv["ColumnLength"].ToString() != "0" && drv["ColumnLength"].ToString().IndexOf("-") < 0)
                        {
                            sb.Append(" MaxLength=\"" + drv["ColumnLength"].ToString() + "\"");
                        }
                    }
                    else
                    {
                        // Do not check for "drv["TableId"].ToString() != string.Empty"
                        if (bEdit) { sb.Append(" Text='<%# " + Robot.DataTypeConvert("Zf", drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), true) + "DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString()" + Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), string.Empty, false) + " %>'"); }
                        if (drv["DataTypeSqlName"].ToString().IndexOf("Char") >= 0 && drv["DisplayMode"].ToString() != "MultiLine" && drv["ColumnLength"].ToString() != string.Empty && drv["ColumnLength"].ToString() != "0" && drv["ColumnLength"].ToString().IndexOf("-") < 0)
                        {
                            sb.Append(" MaxLength=\"" + drv["ColumnLength"].ToString() + "\"");
                        }
                    }
                }
                if (drv["DisplayName"].ToString() == "ComboBox")
                {
                    if (drv["DisplayMode"].ToString() == "AutoComplete") { sb.Append(" Mode=\"A\""); }
                    sb.Append(" OnPostBack=\"cbPostBack\" OnSearch=\"cb" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"");
                }
                if (drv["DisplayMode"].ToString() == "AutoListBox") sb.Append(" searchable ");
                sb.Append(" runat=\"server\" />");
                if (drv["DisplayMode"].ToString() == "AutoListBox") { sb.Append("<asp:TextBox ID=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Hidden\" runat=\"server\" style=\"display:none\" />"); };
                if (drv["DataTypeSqlName"].ToString().IndexOf("Char") >= 0 && drv["DisplayMode"].ToString() == "MultiLine" && drv["ColumnLength"].ToString() != string.Empty && drv["ColumnLength"].ToString() != "0" && drv["ColumnLength"].ToString().IndexOf("-") < 0)
                {
                    sb.Append("<asp:RegularExpressionValidator ControlToValidate=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" display=\"none\" ErrorMessage=\"" + drv["ColumnName"].ToString() + " <= " + drv["ColumnLength"].ToString() + " characters please.\" ValidationExpression=\"^[\\s\\S]{0," + drv["ColumnLength"].ToString() + "}$\" runat=\"server\" />");
                }
                if (drv["ColumnIdentity"].ToString() != "Y")
                {
                    if (drv["RequiredValid"].ToString() == "Y" && ",DropDownList,ComboBox,TextBox,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        sb.Append("<asp:RequiredFieldValidator id=\"cRFV" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" ControlToValidate=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + (drv["DisplayMode"].ToString() == "AutoListBox" ? "Hidden" : "") + "\" display=\"none\" runat=\"server\" />");
                    }
                    if (drv["MaskValid"].ToString() != string.Empty && drv["DisplayName"].ToString() == "TextBox")
                    {
                        sb.Append("<asp:RegularExpressionValidator id=\"cREV" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" ControlToValidate=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" display=\"none\" ValidationExpression=\"" + drv["MaskValid"].ToString() + "\" runat=\"server\" />");
                    }
                    if (drv["RangeValidType"].ToString() != string.Empty && drv["DisplayName"].ToString() == "TextBox")
                    {
                        sb.Append("<asp:RangeValidator id=\"cRV" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" ControlToValidate=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" display=\"none\" MaximumValue=\"" + drv["RangeValidMax"].ToString() + "\" MinimumValue=\"" + drv["RangeValidMin"].ToString() + "\" Type=\"" + drv["RangeValidType"].ToString() + "\" runat=\"server\" />");
                    }
                }
                if (drv["PwdOvride"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                {
                    sb.Append("<asp:TextBox TextMode=\"Password\" autocomplete=\"new-password\" id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd\" CssClass=\"PwdBox\" MaxLength=\"32\" ToolTip=\"Please enter a supervisory override password to proceed!\" AutoPostBack=\"true\" OnTextChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd_TextChanged\" runat=\"server\" visible=\"false\" /><div><asp:Label id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwl\" CssClass=\"inp-lbl\" text=\"Invalid\" runat=\"server\" visible=\"false\" /></div>");
                }
                if (PopTextBox(drv))
                {
                    sb.Append("</td><td><asp:Image id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "E\" ImageUrl=\"~/images/Expand.gif\" CssClass=\"show-expand-button\" runat=\"server\" />");
                }
                if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                {
                    sb.Append("</td><td><asp:imagebutton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search\" onclick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Click\" runat=\"server\" ImageUrl=\"~/Images/Link.gif\" CausesValidation=\"true\" />");
                }
                sb.Append(Environment.NewLine);
                if (PopTextBox(drv) || (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload"))
                {
                    sb.Append("		</td></tr></table>" + Environment.NewLine);
                }
            }
            sb.Append("		</div>");
            return sb;
        }

        private string MakeGrid(string sGrpRow, DataRow dw, Int32 screenId, string screenTitle, DataView dv, DataView dvTab, DataView dvCri, DataView dvGroupCol, CurrPrj CPrj, CurrSrc CSrc)
        {
            int ii;
            //string pMKey = string.Empty;
            //string pMKeyColumn = string.Empty;
            string pDKey = string.Empty;
            string pDKeyColumn = string.Empty;
            string pDKeyDisplayName = string.Empty;
            string pDKeyDisplayMode = string.Empty;
            string pDKeyNumericData = string.Empty;
            string pDKeyDataTypeSysName = string.Empty;
            StringBuilder sbGrid = new StringBuilder();
            string sGrpCol = string.Empty;
            bool bShowHeader = true; if (dw["ShowGridHead"].ToString() == "N") { bShowHeader = false; }
            bool bShowFooter = false;
            int iOffset = 0;
            if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable = 'Y'"; iOffset = dv.Count; dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = string.Empty; }
            foreach (DataRowView drv in dv)
            {
                if (sGrpCol == string.Empty) { sGrpCol = drv["ColCssClass"].ToString(); }
                if (drv["AggregateCd"].ToString() != string.Empty) { bShowFooter = true; break; }
            }
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sbGrid.Append("<div id=\"GridDiv\" class=\"grid-container " + sGrpRow + "\">" + Environment.NewLine);
                sbGrid.Append("<asp:TextBox id=\"isMobile\" CssClass=\"chkMobile\" Text=\"notMobile\" style=\"display:none;\" runat=\"server\" />" + Environment.NewLine);
                sbGrid.Append("<div class=\"viewport " + sGrpCol + "\">" + Environment.NewLine);
                sbGrid.Append("<div class=\"button-container\">" + Environment.NewLine);
                sbGrid.Append(" <asp:Panel id=\"cNaviPanel\" runat=\"server\" visible=\"true\">" + Environment.NewLine);
                sbGrid.Append("		<div class=\"button-grp\"><asp:Button id=\"cGridUploadBtn\" Width=\"0px\" style=\"display:none;\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		<div class=\"button-grp\"><asp:Button id=\"cInsRowButton\" onclick=\"cInsRowButton_Click\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		<div class=\"button-grp\">" + Environment.NewLine);
                sbGrid.Append("		    <div><asp:label ID=\"cGridFtrLabel\" CssClass=\"inp-lbl\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		    <div class=\"grdFindFilter\"><asp:DropDownList id=\"cFindFilter\" CssClass=\"inp-ddl\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		</div>" + Environment.NewLine);
                sbGrid.Append("		<div class=\"button-grp\">" + Environment.NewLine);
                sbGrid.Append("		    <div><asp:label ID=\"cGridFndLabel\" CssClass=\"inp-lbl grdFindLb\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		    <div class=\"grdFind\"><asp:TextBox id=\"cFind\" CssClass=\"inp-txt\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		    <div><asp:Button id=\"cFindButton\" onclick=\"cFindButton_Click\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		</div>" + Environment.NewLine);
                if (dw["ShowGridHead"].ToString() == "N")
                {
                    sbGrid.Append("		<div class=\"button-grp\">" + Environment.NewLine);
                    sbGrid.Append("		    <div><asp:label ID=\"cGridSrtLabel\" CssClass=\"inp-lbl\" runat=\"server\" /></div>" + Environment.NewLine);
                    sbGrid.Append("		    <div class=\"grdSortDiv\"><asp:DropDownList id=\"cSortFilter\" CssClass=\"inp-ddl\" AutoPostBack=\"true\" OnSelectedIndexChanged=\"cSortFilter_SelectedIndexChanged\" runat=\"server\" /></div>" + Environment.NewLine);
                    sbGrid.Append("		    <div><asp:ImageButton ID=\"cSortImg\" CssClass=\"GrdSort\" onClick=\"cSortImg_Click\" Visible=\"false\" runat=\"server\" /></div>" + Environment.NewLine);
                    sbGrid.Append("		</div>" + Environment.NewLine);
                }
                sbGrid.Append("		<div class=\"button-grp\">" + Environment.NewLine);
                sbGrid.Append("		    <div class=\"btnPgGrp\">" + Environment.NewLine);
                sbGrid.Append("		        <div><asp:TextBox id=\"cPgSize\" runat=\"server\" CssClass=\"inp-ctr\" width=\"25px\" /></div>" + Environment.NewLine);
                sbGrid.Append("		        <div><asp:Button id=\"cPgSizeButton\" onclick=\"cPgSizeButton_Click\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		        <div class=\"grdPaging\">" + Environment.NewLine);
                sbGrid.Append("		            <div><asp:Button id=\"cFirstButton\" onclick=\"cFirstButton_Click\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		            <div><asp:Button id=\"cPrevButton\" onclick=\"cPrevButton_Click\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		            <div><asp:TextBox id=\"cGoto\" OnTextChanged=\"cGoto_TextChanged\" AutoPostBack=\"true\" CssClass=\"inp-ctr\" width=\"25px\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		            <div><asp:label id=\"cPageNoLabel\" CssClass=\"inp-lbl\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		            <div><asp:Button id=\"cNextButton\" onclick=\"cNextButton_Click\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		            <div><asp:Button id=\"cLastButton\" CssClass=\"small blue button\" onclick=\"cLastButton_Click\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		        </div>" + Environment.NewLine);
                sbGrid.Append("		        <div><asp:Button id=\"cShowImpButton\" onclick=\"cShowImpButton_Click\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		        <span id=\"grdCount\" class=\"resultTotal\" runat=\"server\"></span>" + Environment.NewLine);
                sbGrid.Append("		    </div>" + Environment.NewLine);
                sbGrid.Append("		</div>" + Environment.NewLine);
                sbGrid.Append("	</asp:Panel>" + Environment.NewLine);
                sbGrid.Append("	<asp:Panel id=\"cImportPwdPanel\" runat=\"server\" visible=\"false\">" + Environment.NewLine);
                sbGrid.Append("		<div class=\"button-grp\">" + Environment.NewLine);
                sbGrid.Append("	        <div><asp:label ID=\"cImpPwdLabel\" CssClass=\"inp-lbl\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		    <div><asp:TextBox TextMode=\"Password\" autocomplete=\"new-password\" id=\"cImportPwd\" CssClass=\"PwdBox\" width=\"250px\" MaxLength=\"32\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		    <div><asp:Button id=\"cContinueButton\" onclick=\"cContinueButton_Click\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		</div>" + Environment.NewLine);
                sbGrid.Append("	</asp:Panel>" + Environment.NewLine);
                sbGrid.Append("	<asp:Panel id=\"cImport\" runat=\"server\" visible=\"false\">" + Environment.NewLine);
                sbGrid.Append("		<div class=\"button-grp\"><asp:FileUpload id=\"cBrowse\" CssClass=\"inp-txt\" runat=\"server\" width=\"250px\" /></div>" + Environment.NewLine);
                sbGrid.Append("		<div class=\"button-grp\"><asp:Button id=\"cBrowseButton\" OnClick=\"cBrowseButton_Click\" Width=\"0px\" style=\"display:none;\" runat=\"server\" /><asp:TextBox id=\"cFNameO\" text=\"\" Width=\"0px\" style=\"display:none;\" runat=\"server\" /><asp:TextBox id=\"cFName\" text=\"\" Width=\"0px\" style=\"display:none;\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		<div class=\"button-grp\">" + Environment.NewLine);
                sbGrid.Append("		    <div><asp:label ID=\"cGridWksLabel\" CssClass=\"inp-lbl\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		    <div><asp:DropDownList id=\"cWorkSheet\" CssClass=\"inp-ddl\" runat=\"server\" style=\"min-width:100px;\" /></div>" + Environment.NewLine);
                sbGrid.Append("		</div>" + Environment.NewLine);
                sbGrid.Append("		<div class=\"button-grp\">" + Environment.NewLine);
                sbGrid.Append("		    <div><asp:label ID=\"cGridStrLabel\" CssClass=\"inp-lbl\" runat=\"server\" /></div>" + Environment.NewLine);
                sbGrid.Append("		    <div>" + Environment.NewLine);
                sbGrid.Append("		        <asp:TextBox id=\"cStartRow\" CssClass=\"inp-ctr\" text=\"2\" runat=\"server\" width=\"30px\" />" + Environment.NewLine);
                sbGrid.Append("		        <asp:ImageButton id=\"cSchemaImage\" ImageUrl=\"~/images/Schema.gif\" runat=\"server\" />" + Environment.NewLine);
                sbGrid.Append("		        <asp:Button id=\"cImportButton\" onclick=\"cImportButton_Click\" runat=\"server\" />" + Environment.NewLine);
                sbGrid.Append("		    </div>" + Environment.NewLine);
                sbGrid.Append("		    <div><asp:Button id=\"cHideImpButton\" onclick=\"cHideImpButton_Click\" runat=\"server\" CausesValidation=\"true\" /></div>" + Environment.NewLine);
                sbGrid.Append("		</div>" + Environment.NewLine);
                sbGrid.Append("	</asp:Panel>" + Environment.NewLine);
                sbGrid.Append("</div>" + Environment.NewLine);
                sbGrid.Append("<div class=\"ListView\">" + Environment.NewLine);
                sbGrid.Append("	<asp:ListView id=\"c" + dw["ProgramName"].ToString() + "Grid\" DataKeyNames=\"");
                foreach (DataRowView drv in dv)
                {
                    if (drv["PrimaryKey"].ToString() == "Y")
                    {
                        sbGrid.Append(drv["ColumnName"].ToString() + drv["TableId"].ToString());
                        //if ("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                        //{
                        //    pMKey = drv["ColumnName"].ToString();
                        //    pMKeyColumn = drv["ColumnName"].ToString() + drv["TableId"].ToString();
                        //}
                        pDKey = drv["ColumnName"].ToString();
                        pDKeyColumn = drv["ColumnName"].ToString() + drv["TableId"].ToString();
                        pDKeyDisplayName = drv["DisplayName"].ToString();
                        pDKeyDisplayMode = drv["DisplayMode"].ToString();
                        pDKeyNumericData = drv["NumericData"].ToString();
                        pDKeyDataTypeSysName = drv["DataTypeSysName"].ToString();
                        break;
                    }
                }
                sbGrid.Append("\" OnItemCommand=\"c" + dw["ProgramName"].ToString() + "Grid_OnItemCommand\" OnSorting=\"c" + dw["ProgramName"].ToString() + "Grid_OnSorting\" OnPreRender=\"c" + dw["ProgramName"].ToString() + "Grid_OnPreRender\" OnPagePropertiesChanging=\"c" + dw["ProgramName"].ToString() + "Grid_OnPagePropertiesChanging\" OnItemEditing=\"c" + dw["ProgramName"].ToString() + "Grid_OnItemEditing\" OnItemCanceling=\"c" + dw["ProgramName"].ToString() + "Grid_OnItemCanceling\" OnItemDeleting=\"c" + dw["ProgramName"].ToString() + "Grid_OnItemDeleting\" OnItemDataBound=\"c" + dw["ProgramName"].ToString() + "Grid_OnItemDataBound\" OnLayoutCreated=\"c" + dw["ProgramName"].ToString() + "Grid_OnLayoutCreated\" OnItemUpdating=\"c" + dw["ProgramName"].ToString() + "Grid_OnItemUpdating\" runat=\"server\">" + Environment.NewLine);

                ii = 0;
                // temporary:
                StringBuilder sbHead = new StringBuilder();
                StringBuilder sbItem = new StringBuilder();
                StringBuilder sbEdit = new StringBuilder();
                StringBuilder sbFoot = new StringBuilder();
                // aggregate:
                StringBuilder ssHead = new StringBuilder();
                StringBuilder ssItem = new StringBuilder();
                StringBuilder ssEdit = new StringBuilder();
                StringBuilder ssFoot = new StringBuilder();
                foreach (DataRowView drv in dv)
                {
                    if (drv["GridGrpCd"].ToString() == "N" || drv["GridGrpCd"].ToString() == "")
                    {
                        if (sbHead.Length > 0)
                        {
                            sbHead.Append("</div>" + Environment.NewLine);
                            ssHead.Append("    <td>" + Environment.NewLine + sbHead.ToString() + "    </td>" + Environment.NewLine);
                            sbHead.Remove(0, sbHead.Length);
                        };
                        if (sbItem.Length > 0)
                        {
                            sbItem.Append("</div>" + Environment.NewLine);
                            ssItem.Append("    <td>" + Environment.NewLine + sbItem.ToString() + "    </td>" + Environment.NewLine);
                            sbItem.Remove(0, sbItem.Length);
                        };
                        if (sbEdit.Length > 0)
                        {
                            sbEdit.Append("</div>" + Environment.NewLine);
                            ssEdit.Append("    <td>" + Environment.NewLine + sbEdit.ToString() + "    </td>" + Environment.NewLine);
                            sbEdit.Remove(0, sbEdit.Length);
                        };
                        if (sbFoot.Length > 0)
                        {
                            sbFoot.Append("</div>" + Environment.NewLine);
                            ssFoot.Append("    <td>" + Environment.NewLine + sbFoot.ToString() + "    </td>" + Environment.NewLine);
                            sbFoot.Remove(0, sbFoot.Length);
                        };
                    }
                    if (drv["GridGrpCd"].ToString() != "I")
                    {
                        if (sbHead.Length > 0)
                        {
                            sbHead.Append("</div>" + Environment.NewLine);
                            if (drv["GridGrpCd"].ToString() == "Y" || drv["GridGrpCd"].ToString() == "B" || drv["GridGrpCd"].ToString() == "") sbHead.Append("		<div></div>" + Environment.NewLine);
                        };
                        sbHead.Append("		<div class='GrdOuter' runat=\"server\">");
                        if (sbItem.Length > 0)
                        {
                            sbItem.Append("</div>" + Environment.NewLine);
                            if (drv["GridGrpCd"].ToString() == "Y" || drv["GridGrpCd"].ToString() == "B" || drv["GridGrpCd"].ToString() == "") sbItem.Append("		<div></div>" + Environment.NewLine);
                        };
                        sbItem.Append("		<div class='GrdOuter' runat=\"server\">");
                        if (sbEdit.Length > 0)
                        {
                            sbEdit.Append("</div>" + Environment.NewLine);
                            if (drv["GridGrpCd"].ToString() == "Y" || drv["GridGrpCd"].ToString() == "B" || drv["GridGrpCd"].ToString() == "") sbEdit.Append("		<div></div>" + Environment.NewLine);
                        };
                        sbEdit.Append("		<div class='GrdOuter' runat=\"server\">");
                        if (sbFoot.Length > 0)
                        {
                            sbFoot.Append("</div>" + Environment.NewLine);
                            if (drv["GridGrpCd"].ToString() == "Y" || drv["GridGrpCd"].ToString() == "B" || drv["GridGrpCd"].ToString() == "") sbFoot.Append("		<div></div>" + Environment.NewLine);
                        };
                        sbFoot.Append("		<div class='GrdOuter' runat=\"server\">");
                    }

                    sbHead.Append("<div class='GrdInner" + (drv["LabelCss"].ToString().StartsWith(".") ? " " + drv["LabelCss"].ToString().Substring(1) : string.Empty) + (drv["HideOnTablet"].ToString() == "Y" ? " HideObjOnTablet" : string.Empty) + (drv["HideOnMobile"].ToString() == "Y" ? " HideObjOnMobile" : string.Empty) + "' style='" + (string.IsNullOrEmpty(drv["ColumnSize"].ToString()) ? string.Empty : "max-width:" + drv["ColumnSize"].ToString() + "px;") + AlignmentTranslate(drv["ColumnJustify"].ToString()) + "' runat=\"server\">" + Environment.NewLine);
                    if (",Button,ImageButton,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString()))
                    {
                        sbHead.Append("			<asp:LinkButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hl\" CssClass=\"GrdHead\" onClick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hl_Click\"");
                        if (!string.IsNullOrEmpty(drv["LabelCss"].ToString()) && !drv["LabelCss"].ToString().StartsWith(".")) { sbHead.Append(" style=\"" + drv["LabelCss"].ToString() + "\""); }
                        sbHead.Append(" runat=\"server\" /><asp:Image id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hi\" runat=\"server\" />");
                        if (drv["DisplayMode"].ToString() == "CheckBoxAll") { sbHead.Append("<asp:CheckBox id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hc\" CssClass=\"GrdHead\" AutoPostBack=\"true\" onCheckedChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hc_CheckedChanged\" runat=\"server\" />"); }
                        sbHead.Append(Environment.NewLine);
                    }
                    sbHead.Append("		</div>");

                    sbItem.Append("<div class='GrdInner" + (drv["ContentCss"].ToString().StartsWith(".") ? " " + drv["ContentCss"].ToString().Substring(1) : string.Empty) + (drv["HideOnTablet"].ToString() == "Y" ? " HideObjOnTablet" : string.Empty) + (drv["HideOnMobile"].ToString() == "Y" ? " HideObjOnMobile" : string.Empty) + "' style='" + (string.IsNullOrEmpty(drv["ColumnSize"].ToString()) ? string.Empty : "max-width:" + drv["ColumnSize"].ToString() + "px;") + AlignmentTranslate(drv["ColumnJustify"].ToString()) + "' visible=\"<%# GridColumnVisible(" + (iOffset + ii).ToString() + ") %>\" onclick='GridEdit(\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\")' runat=\"server\">" + Environment.NewLine);
                    if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sbItem.Append("			<asp:HyperLink"); }
                    else if (",CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sbItem.Append("			<asp:CheckBox"); }
                    else if (",Button,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sbItem.Append("			<asp:Button"); }
                    else if (",ImageButton,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sbItem.Append("			<asp:ImageButton"); }
                    else { sbItem.Append("			<asp:Label"); }
                    if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0)
                    {
                        sbItem.Append(" id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "l\"");
                    }
                    // HyperLink Display:
                    if (",HyperLink,HyperPopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                    {
                        if (!string.IsNullOrEmpty(drv["DefaultValue"].ToString()))
                        {
                            sbItem.Append(" Text='" + drv["DefaultValue"].ToString() + "'");
                        }
                        else
                        {
                            sbItem.Append(" Text='<%# DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString().Trim() == string.Empty ? string.Empty : DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\") %>'");
                        }
                    }
                    else if (",ImageLink,ImagePopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                    {
                        if (!string.IsNullOrEmpty(drv["DefaultValue"].ToString()))
                        {
                            sbItem.Append(" ImageUrl='" + Utils.AddTilde(drv["DefaultValue"].ToString()) + "'");
                        }
                        else if (drv["ColumnId"].ToString() == drv["DdlKeyColumnId"].ToString())
                        {
                            sbItem.Append(" ImageUrl='~/images/GridLink.gif'");
                        }
                        else
                        {
                            sbItem.Append(" ImageUrl='<%# RO.Common3.Utils.AddTilde(GetUrlWithQSHash(DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString())) %>'");
                        }
                    }
                    // Check "drv["DdlRefColumnId"].ToString() == string.Empty" later:
                    if (",ImageButton,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                    {
                        if (drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                        {
                            sbItem.Append(" ImageUrl='<%# DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString().Trim().Equals(string.Empty) ? \"../images/DefaultImg.png\" : RO.Common3.Utils.BlobPlaceHolder((DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\") as byte[])??(new byte[1]),true) %>'");
                            // Need both width and height to function properly:
                            if (drv["ColumnSize"].ToString() != string.Empty && drv["ColumnHeight"].ToString() != string.Empty)
                            {
                                sbItem.Append(" style=\"max-width:" + drv["ColumnSize"].ToString() + "px; max-height:" + drv["ColumnHeight"].ToString() + "px;\"");
                            }
                        }
                        else if (string.IsNullOrEmpty(drv["ColumnId"].ToString()))
                        {
                            if (drv["DefaultValue"].ToString() == string.Empty)
                            {
                                sbItem.Append(" ImageUrl=\"\" visible=\"false\"");
                            }
                            else
                            {
                                sbItem.Append(" ImageUrl=\"" + Utils.AddTilde(drv["DefaultValue"].ToString()) + "\" visible=\"true\"");
                            }
                        }
                        else
                        {
                            sbItem.Append(" ImageUrl='<%# RO.Common3.Utils.AddTilde(GetUrlWithQSHash(DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString())) %>'");
                            if (drv["ColumnSize"].ToString() != string.Empty) { sbItem.Append(" max-width=\"" + drv["ColumnSize"].ToString() + "px\""); }
                            sbItem.Append(" visible='<%# !DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString().Trim().Equals(string.Empty) %>'");
                        }
                    }
                    else if (drv["DisplayMode"].ToString() != "Password" && drv["DisplayName"].ToString() != "HyperLink")
                    {
                        if (",CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        {
                            sbItem.Append(" Enabled='<%# AllowEdit(LcAuth,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\") && " + (dw["ScreenTypeName"].ToString() == "I2" ? "CanAct((char) \"S\"[0])" : "AllowRowEdit(GetAuthRow(),DataBinder.Eval(Container.DataItem,\"" + pDKeyColumn + "\").ToString())") + " %>'");
                            sbItem.Append(" checked='<%# base.GetBool(DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString().Replace(\"\\r\\n\",\"<br />\").Replace(\"\\r\",\"<br />\").Replace(\"\\n\",\"<br />\").Replace(\"  \",HtmlSpace())) %>'");
                        }
                        else
                        {
                            sbItem.Append(" Text='<%# ");
                            if (drv["DisplayMode"].ToString().ToLower() == "currency")
                            {
                                sbItem.Append("base.fxCurrency(DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString()");
                                sbItem.Append(string.IsNullOrEmpty(drv["DdlKeyColumnName"].ToString()) ? ",base.LUser.Culture" : ",DataBinder.Eval(Container.DataItem,\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "\").ToString()");
                                sbItem.Append(string.IsNullOrEmpty(drv["DdlRefColumnName"].ToString()) ? ",base.LUser.Culture)" : ",DataBinder.Eval(Container.DataItem,\"" + drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString() + "\").ToString())");
                            }
                            else if (drv["DisplayMode"].ToString().ToLower() == "encryptedtextbox")
                            {
                                sbItem.Append("base.fxEncryptedText(" + "DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString()");
                                if (drv["DataTypeSysName"].ToString() == "String") { sbItem.Append(".Replace(\"\\r\\n\",\"<br />\").Replace(\"\\r\",\"<br />\").Replace(\"\\n\",\"<br />\").Replace(\"  \",HtmlSpace())"); }
                                sbItem.Append(")");
                            }
                            else
                            {
                                sbItem.Append(Robot.DataTypeConvert("Zf", drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), true) + "DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString()");
                                if (drv["DataTypeSysName"].ToString() == "String") { sbItem.Append(".Replace(\"\\r\\n\",\"<br />\").Replace(\"\\r\",\"<br />\").Replace(\"\\n\",\"<br />\").Replace(\"  \",HtmlSpace())"); }
                                sbItem.Append(Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), string.Empty, false));
                            }
                            sbItem.Append(" %>'");
                        }
                    }
                    if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        sbItem.Append(" Visible=\"false\" runat=\"server\" />" + Environment.NewLine);
                        sbItem.Append("			<asp:Label id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "l\" text='<%# DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\") %>'");
                    }
                    if (drv["DisplayName"].ToString() == "Button")
                    {
                        sbItem.Append(" CssClass=\"small blue button\"");
                        if (string.IsNullOrEmpty(drv["ColumnId"].ToString()) && drv["ColumnSize"].ToString() != string.Empty) { sbItem.Append(" max-width=\"" + drv["ColumnSize"].ToString() + "px\""); }
                    }
                    else if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 && drv["DdlKeyColumnName"].ToString() != string.Empty && drv["DdlKeyTableId"].ToString() != string.Empty)
                    {
                        sbItem.Append(" CssClass='<%# DataBinder.Eval(Container.DataItem,\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "URL\").ToString().Trim() == string.Empty ? ");
                        if (drv["ColumnJustify"].ToString() == "R" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0) { sbItem.Append("\"GrdTxtLb\" : \"GrdTxtLn\""); }
                        else if (drv["ColumnJustify"].ToString() == "C" || drv["DisplayName"].ToString() == "CheckBox") { sbItem.Append("\"GrdBoxLb\" : \"GrdBoxLn\""); }
                        else if (drv["ColumnWrap"].ToString() == "Y") { sbItem.Append("\"GrdTxtLb\" : \"GrdTxtLn\""); }
                        else { sbItem.Append("\"GrdNwrLb\" : \"GrdNwrLn\""); }
                        sbItem.Append(" %>'");
                    }
                    else if ("progressbar,starrating".IndexOf(drv["DisplayMode"].ToString().ToLower()) >= 0)
                    {
                        sbItem.Append(" CssClass=\"" + drv["DisplayMode"].ToString().ToLower() + "\"");
                        if (drv["ColumnSize"].ToString() != string.Empty) { sbItem.Append(" max-width=\"" + drv["ColumnSize"].ToString() + "px\""); }
                    }
                    else if (",CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0)
                    {
                        sbItem.Append(" CssClass=");
                        if (drv["ColumnJustify"].ToString() == "R" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0) { sbItem.Append("\"GrdTxtLb\""); }
                        else if (drv["ColumnJustify"].ToString() == "C" || drv["DisplayName"].ToString() == "CheckBox") { sbItem.Append("\"GrdBoxLb\""); }
                        else if (drv["ColumnWrap"].ToString() == "Y") { sbItem.Append("\"GrdTxtLb\""); }
                        else { sbItem.Append("\"GrdNwrLb\""); }
                    }
                    if (drv["ColumnHeight"].ToString() != string.Empty && ",multiline,imagebutton,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") < 0)
                    {
                        sbItem.Append(" height=\"" + drv["ColumnHeight"].ToString() + "px\"");
                    }
                    if (",Button,ImageButton,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        // AutoPostBack not available for Button and ImageButton:
                        sbItem.Append(" OnClick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click\"");
                        // must check read only on data bind
                        sbItem.Append(" Enabled=\"<%# GridColumnEnable(" + (iOffset + ii).ToString() + ") %>\"");
                        sbItem.Append(" CommandArgument='<%# DataBinder.Eval(Container.DataItem,\"" + pDKeyColumn + "\").ToString() %>'");
                    }
                    else if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        if (!string.IsNullOrEmpty(drv["HyperLinkUrl"].ToString()))   // Static Link URL override Key Column.
                        {
                            if (drv["HyperLinkUrl"].ToString().ToLower().IndexOf("javascript:") >= 0)
                            {
                                sbItem.Append(" OnClick=\"" + drv["HyperLinkUrl"].ToString().Substring(drv["HyperLinkUrl"].ToString().ToLower().IndexOf("javascript:") + 11) + "\"");
                            }
                            else if (",HyperPopUp,ImagePopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 && !drv["HyperLinkUrl"].ToString().ToLower().StartsWith("mailto"))
                            {
                                sbItem.Append(" OnClick=\"SearchLink('" + drv["HyperLinkUrl"].ToString() + "','','',''); return stopEvent(this,event);\" NavigateUrl=\"#\"");
                            }
                            else
                            {
                                sbItem.Append(" NavigateUrl=\"" + Utils.AddTilde(drv["HyperLinkUrl"].ToString()) + "\"");
                            }
                        }
                        else if (drv["DdlKeyColumnName"].ToString() != string.Empty && drv["DdlKeyTableId"].ToString() != string.Empty)  // Dynamic URL present.
                        {
                            if (",HyperPopUp,ImagePopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                            {
                                sbItem.Append(" NavigateUrl=\"#\" OnClick='<%# \"SearchLink(&#39;\" + DataBinder.Eval(Container.DataItem,\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "URL\") + \"&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;); return stopEvent(this,event);\" %>'");
                            }
                            else
                            {
                                sbItem.Append(" NavigateUrl='<%# RO.Common3.Utils.AddTilde(GetUrlWithQSHash(DataBinder.Eval(Container.DataItem,\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "URL\").ToString())) %>'");
                            }
                        }
                        sbItem.Append(" visible='<%# !DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString().Trim().Equals(string.Empty) %>'");
                    }
                    if (!string.IsNullOrEmpty(drv["ContentCss"].ToString()) && !drv["ContentCss"].ToString().StartsWith(".")) { sbItem.Append(" style=\"" + drv["ContentCss"].ToString() + "\""); }
                    sbItem.Append(" runat=\"server\" />" + Environment.NewLine + "		</div>");
                    sbEdit = MkEditInsr(drv, sbEdit, iOffset, ii, pDKeyColumn, true);
                    sbFoot.Append("<div class='GrdInner" + (drv["LabelCss"].ToString().StartsWith(".") ? " " + drv["LabelCss"].ToString().Substring(1) : string.Empty) + (drv["HideOnTablet"].ToString() == "Y" ? " HideObjOnTablet" : string.Empty) + (drv["HideOnMobile"].ToString() == "Y" ? " HideObjOnMobile" : string.Empty) + "' style='" + (string.IsNullOrEmpty(drv["ColumnSize"].ToString()) ? string.Empty : "max-width:" + drv["ColumnSize"].ToString() + "px;") + AlignmentTranslate(drv["ColumnJustify"].ToString()) + "' runat=\"server\">" + Environment.NewLine);
                    sbFoot.Append("		    <asp:Label id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "fl\" class='GrdFoot' runat=\"server\" />" + Environment.NewLine);
                    sbFoot.Append("		</div>");
                    ii = ii + 1;
                }
                if (sbHead.Length > 0)
                {
                    sbHead.Append("</div>" + Environment.NewLine);
                    ssHead.Append("    <td>" + Environment.NewLine + sbHead.ToString() + "    </td>" + Environment.NewLine);
                    sbHead.Remove(0, sbHead.Length);
                };
                if (sbItem.Length > 0)
                {
                    sbItem.Append("</div>" + Environment.NewLine);
                    ssItem.Append("    <td>" + Environment.NewLine + sbItem.ToString() + "    </td>" + Environment.NewLine);
                    sbItem.Remove(0, sbItem.Length);
                };
                if (sbEdit.Length > 0)
                {
                    sbEdit.Append("</div>" + Environment.NewLine);
                    ssEdit.Append("    <td>" + Environment.NewLine + sbEdit.ToString() + "    </td>" + Environment.NewLine);
                    sbEdit.Remove(0, sbEdit.Length);
                };
                if (sbFoot.Length > 0)
                {
                    sbFoot.Append("</div>" + Environment.NewLine);
                    ssFoot.Append("    <td>" + Environment.NewLine + sbFoot.ToString() + "    </td>" + Environment.NewLine);
                    sbFoot.Remove(0, sbFoot.Length);
                };

                sbGrid.Append("	<LayoutTemplate>" + Environment.NewLine);
                sbGrid.Append("	<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\">" + Environment.NewLine);
                sbGrid.Append("	<tr id=\"c" + dw["ProgramName"].ToString() + "GridHeader\" class=\"GrdHead\"");
                if (bShowHeader) { sbGrid.Append(" visible=\"true\""); } else { sbGrid.Append(" visible=\"false\""); }
                sbGrid.Append(" runat=\"server\">" + Environment.NewLine + ssHead);
                if (dw["HasDeleteAll"].ToString() == "Y")
                {
                    sbGrid.Append("    <td><asp:linkbutton id=\"cDeleteAllButton\" CssClass=\"GrdDelAll\" tooltip=\"DELETE ALL\" onclick=\"cDeleteAllButton_Click\"");
                    if (dw["ViewOnly"].ToString() == "Y") { sbGrid.Append(" Visible=\"false\""); }
                    sbGrid.Append(" runat=\"server\" onclientclick='GridDelete()' /></td>" + Environment.NewLine);
                }
                else { sbGrid.Append("    <td>&nbsp;</td>" + Environment.NewLine); }
                sbGrid.Append("	</tr>" + Environment.NewLine);
                sbGrid.Append("	<tr id=\"itemPlaceholder\" runat=\"server\"></tr>" + Environment.NewLine);
                sbGrid.Append("	<tr id=\"c" + dw["ProgramName"].ToString() + "GridFooter\" class=\"GrdFoot\"");
                if (bShowFooter) { sbGrid.Append(" visible=\"true\""); } else { sbGrid.Append(" visible=\"false\""); }
                sbGrid.Append(" runat=\"server\">" + Environment.NewLine + ssFoot);
                sbGrid.Append("    <td>&nbsp;</td>" + Environment.NewLine);
                sbGrid.Append("	</tr></table></LayoutTemplate>" + Environment.NewLine);
                sbGrid.Append("	<ItemTemplate>" + Environment.NewLine);
                sbGrid.Append("	<tr id=\"c" + dw["ProgramName"].ToString() + "GridRow\" class='<%# Container.DisplayIndex % 2 == 0 ? \"GrdItm\" : \"GrdAlt\" %>' runat=\"server\">" + Environment.NewLine);
                sbGrid.Append(ssItem);
                sbGrid.Append("	<td>" + Environment.NewLine);
                sbGrid.Append("       <asp:LinkButton ID=\"c" + dw["ProgramName"].ToString() + "GridEdit\" style=\"display:none;\" CausesValidation=\"true\" CommandName=\"Edit\" runat=\"server\" />" + Environment.NewLine);
                sbGrid.Append("       <asp:LinkButton ID=\"c" + dw["ProgramName"].ToString() + "GridDelete\" CssClass=\"GrdDel\" tooltip=\"DELETE\" CommandName=\"Delete\" onclientclick='GridDelete()' runat=\"server\" />" + Environment.NewLine);
                sbGrid.Append("	</td>" + Environment.NewLine);
                sbGrid.Append("	</tr>" + Environment.NewLine);
                sbGrid.Append("	</ItemTemplate>" + Environment.NewLine);
                sbGrid.Append("	<EditItemTemplate>" + Environment.NewLine);
                sbGrid.Append("	<tr class=\"GrdEdtTmp\" runat=\"server\">" + Environment.NewLine);
                sbGrid.Append(ssEdit);
                sbGrid.Append("	<td>" + Environment.NewLine);
                sbGrid.Append("       <asp:LinkButton ID=\"c" + dw["ProgramName"].ToString() + "GridCancel\" CssClass=\"GrdCan\" tooltip=\"CANCEL\" OnClientClick=\"GridCancel();\" CausesValidation=\"true\" CommandName=\"Cancel\" runat=\"server\" />" + Environment.NewLine);
                sbGrid.Append("       <asp:LinkButton ID=\"c" + dw["ProgramName"].ToString() + "GridUpdate\" style=\"display:none;\" CommandName=\"Update\" runat=\"server\" />" + Environment.NewLine);
                sbGrid.Append("	</td>" + Environment.NewLine);
                sbGrid.Append("	</tr>" + Environment.NewLine);
                sbGrid.Append("	</EditItemTemplate>" + Environment.NewLine);
                sbGrid.Append("	<EmptyDataTemplate><div class=\"GrdHead\" style=\"text-align:center;padding:3px 0;\"><span>No data currently available.</span></div></EmptyDataTemplate>" + Environment.NewLine);
                sbGrid.Append("	</asp:ListView>" + Environment.NewLine);
                sbGrid.Append("	<asp:DataPager ID=\"c" + dw["ProgramName"].ToString() + "GridDataPager\" runat=\"server\" Visible=\"false\" PagedControlID=\"c" + dw["ProgramName"].ToString() + "Grid\"></asp:DataPager>" + Environment.NewLine);
                sbGrid.Append("</div></div></div>" + Environment.NewLine);
            }
            return sbGrid.ToString();
        }

        private StringBuilder MakeAscx(DataRow dw, Int32 screenId, string screenTitle, DataView dv, DataView dvTab, DataView dvCri, DataView dvGroupCol, CurrPrj CPrj, CurrSrc CSrc, string clientFrwork)
		{
			//string pMKey = string.Empty;
            string pMKeyColumn = string.Empty;
			StringBuilder sb = new StringBuilder();
            string sGrpRow = string.Empty;
            string sGridTab = string.Empty;
            string sGrid = string.Empty;
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = string.Empty; }
                foreach (DataRowView drv in dv)
                {
                    if (sGridTab == string.Empty) { sGridTab = drv["TabFolderId"].ToString(); }
                    if (sGrpRow == string.Empty) { sGrpRow = drv["RowCssClass"].ToString(); break; }
                }
                sGrid = MakeGrid(sGrpRow, dw, screenId, screenTitle, dv, dvTab, dvCri, dvGroupCol, CPrj, CSrc);
            }
			sb.Append("<%@ Control Language=\"c#\" Inherits=\"" + CPrj.EntityCode + ".Web." + dw["ProgramName"].ToString() + "Module\" CodeFile=\"" + dw["ProgramName"].ToString() + "Module.ascx.cs\" CodeFileBaseClass=\"RO.Web.ModuleBase\" %>" + Environment.NewLine);
			sb.Append("<%@ Register TagPrefix=\"ajwced\" Assembly=\"AjaxControlToolkit\" Namespace=\"AjaxControlToolkit.HTMLEditor\" %>" + Environment.NewLine);
			sb.Append("<%@ Register TagPrefix=\"rcasp\" NameSpace=\"RoboCoder.WebControls\" Assembly=\"WebControls, Culture=neutral\" %>" + Environment.NewLine);
			sb.Append("<%@ Register TagPrefix=\"Module\" TagName=\"Help\" Src=\"HelpModule.ascx\" %>" + Environment.NewLine);
            sb.Append("<script type=\"text/javascript\" lang=\"javascript\">" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("	initPageLoad=true;" + Environment.NewLine);
            }
            else
            {
                sb.Append("	initPageLoad=false;" + Environment.NewLine);
            }
            sb.Append("	ServerDateFormat = { shortFormat: \"<%= System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern %>\" , longFormat: \"<%= System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongDatePattern %>\"};" + Environment.NewLine);
            sb.Append("	if(IsMobile()){ var $body = jQuery('body');" + Environment.NewLine);
            sb.Append("	    $(document).live('mousedown', '.ui-button, input[type=\"text\"], select, textarea', function(e) { var target = $( e.target );" + Environment.NewLine);
            sb.Append("	        if (target.is( '.ui-button, input[type=\"text\"], select, textarea')) { $body.addClass('mobilekeyPop'); }" + Environment.NewLine);
            sb.Append("	        if((target.is( '.ui-button, select, textarea')||(e.target.tagName == 'INPUT' && e.target.type == 'text')) && !e.target.alreadyClicked){ target.on('focus', function(e) { $body.addClass('mobilekeyPop'); }); e.target.alreadyClicked = true; }" + Environment.NewLine);
            sb.Append("	    }).on('blur', 'input[type=\"text\"], select, textarea', function(e) { $body.removeClass('mobilekeyPop'); });" + Environment.NewLine);
            sb.Append("	}" + Environment.NewLine);
            sb.Append("	window.matchMedia = window.matchMedia || function(x) { return {\"matches\":0}; };" + Environment.NewLine);
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("      Sys.Application.add_load(function () { if (typeof(old_Page_ClientValidate)!='undefined' || typeof(Page_ClientValidate) =='undefined') return; try { old_Page_ClientValidate = Page_ClientValidate;} catch(e){}; Page_ClientValidate = function (g) {if (typeof(old_Page_ClientValidate) == 'function') {$.watermark.hideAll(); Page_BlockSubmit = false && !old_Page_ClientValidate(g);} else return true; if (Page_BlockSubmit) { ValidateThisModule(<%= this.ClientID %>); $('#<%=cValidSummary.ClientID%>:visible').hide();} ; if (Page_BlockSubmit && $('#<%=bPgDirty.ClientID%>').val() == 'Y') {$('#<%=bConfirm.ClientID%>').val('Y');}; return !Page_BlockSubmit;}});" + Environment.NewLine);
            }
            else
            {
                sb.Append("      $(document).ready(function () { var old = null; try {old = Page_ClientValidate;} catch(e){}; Page_ClientValidate = function (g) {if (old && typeof(old) == 'function') {$.watermark.hideAll();Page_BlockSubmit = false && !old(g);} else return true; if (Page_BlockSubmit) { ValidateThisModule(<%= this.ClientID %>); $('#<%=cValidSummary.ClientID%>:visible').hide();} ; if (Page_BlockSubmit && $('#<%=bPgDirty.ClientID%>').val() == 'Y') {$('#<%=bConfirm.ClientID%>').val('Y');}; return !Page_BlockSubmit;}});" + Environment.NewLine);
            }
            sb.Append("	Sys.Application.add_load(function () { $('input[type=hidden]').each(function (i, e) { try { e.defaultValue = e.value; } catch (er) { } }); WatermarkInput(<%= this.ClientID %>,'<%= PanelUpd.ClientID %>');});" + Environment.NewLine);
            sb.Append("	Sys.Application.add_load(function () { var hlp={}; $('a.GrdHead').each(function(i,e){var ids = ($(this).attr('id')||'').split('_'); hlp[ids[ids.length-1].replace(/hl$/,'l')] = $(this).attr('title');});$('span.GrdTxtLb,a.GrdTxtLn,a.GrdBoxLn').each(function (i, e) {try { var style = ($(this).attr('style')||'').replace(/height/i, 'max-height'); var ids = ($(this).attr('id')||'').split('_'); $(this).attr('title', hlp[ids[ids.length-1]]).attr('style', style); } catch (e) { } }); });" + Environment.NewLine);
            sb.Append("	Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler)" + Environment.NewLine);
            sb.Append("	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler)" + Environment.NewLine);
            sb.Append("	Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ChkExpNow)" + Environment.NewLine);
            sb.Append("	Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(ChkPgDirty)" + Environment.NewLine);
            sb.Append("	Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequestHandler)" + Environment.NewLine);
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("	function GridUpload() { document.getElementById('<%=cGridUploadBtn.ClientID %>').click() }" + Environment.NewLine);
                sb.Append("	function GridEdit(cn) { document.getElementById('<%=bConfirm.ClientID %>').value = 'N'; colNam=cn; }" + Environment.NewLine);
                sb.Append("	function GridDelete() { document.getElementById('<%=bPgDirty.ClientID %>').value='Y'; ChkPgDirty(); document.getElementById('<%=bConfirm.ClientID %>').value='N';colNam='DeleteLink';}" + Environment.NewLine);
                sb.Append("	function GridCancel() { Page_Validators=[]; document.getElementById('<%=bConfirm.ClientID %>').value='N';}" + Environment.NewLine);
                sb.Append("	var xPos, yPos;" + Environment.NewLine);
                sb.Append("	function SaveScroll() { xPos = $(document).scrollLeft(); yPos = $(document).scrollTop(); }" + Environment.NewLine);
                sb.Append("	function RestoreScroll() { setTimeout(function() {$(document).scrollLeft(xPos);$(document).scrollTop(yPos);}, 0); }" + Environment.NewLine);
                sb.Append("	Sys.Application.add_load(function () {if(window.matchMedia(\"screen and (max-width: 1024px)\").matches){if (window.matchMedia(\"screen and (max-width: 767px)\").matches){AppendSingleTd();}else{$('.GrdEdtLabelText').hide();if($('.GrdEdtTmp').length > 0){$('.GrdHead .HideObjOnTablet').addClass(' ShowObjHeader');}}}else{ $('.GrdEdtLabelText').hide(); $('.GrdHead .HideObjOnTablet').removeClass(' ShowObjHeader');}});" + Environment.NewLine);
                sb.Append("	$(window).resize(function () { if(window.matchMedia(\"screen and (max-width: 1024px)\").matches){ if (window.matchMedia(\"screen and (max-width: 767px)\").matches){ AppendSingleTd();}else{$('.GrdEdtLabelText').hide();if($('.GrdEdtTmp').length > 0){$('.GrdHead .HideObjOnTablet').addClass(' ShowObjHeader');}AppendOrigTd();}} else {$('.GrdEdtLabelText').hide();$('.GrdHead .HideObjOnTablet').removeClass(' ShowObjHeader');}});" + Environment.NewLine);
            }
            sb.Append("	function NoConfirm() {document.getElementById('<%=bConfirm.ClientID%>').value = 'N';}" + Environment.NewLine);
            sb.Append("	function ChkPgDirty()" + Environment.NewLine);
            sb.Append("	{" + Environment.NewLine);
            sb.Append("		var x = document.getElementById('<%=bPgDirty.ClientID%>');" + Environment.NewLine);
            sb.Append("		var y = document.getElementById('<%=cPgDirty.ClientID%>');" + Environment.NewLine);
            sb.Append("		if (y != null) {if (x != null && x.value == 'Y') {y.style.visibility = '';} else {y.style.visibility = 'hidden';}}" + Environment.NewLine);
            sb.Append("	}" + Environment.NewLine);
            sb.Append("	function initializeRequestHandler(sender, args) {if (!fConfirm2('<%=bPgDirty.ClientID%>','<%=bConfirm.ClientID%>','<%=aNam.ClientID%>','<%=aVal.ClientID%>')) {args.set_cancel(true);} else try {$.watermark.hideAll();} catch (e) { }}" + Environment.NewLine);
            sb.Append("	function beginRequestHandler(sender, e) { e.get_postBackElement().disabled=true;");
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append(" SaveScroll();"); }
            sb.Append(" ShowProgress(); document.body.style.cursor='wait'; }" + Environment.NewLine);
            sb.Append("	function endRequestHandler() { initPageLoad=true;");
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append(" RestoreScroll();"); }
            sb.Append(" HideProgress(); document.body.style.cursor='auto'; var v = $('#<%=cValidSummary.ClientID%>:visible'); if (v.length > 0 && typeof(Page_Validators) != 'undefined' && $(Page_Validators).length > 0) {ValidateThisModule(<%= this.ClientID %>);v.hide();}; }" + Environment.NewLine);
            sb.Append("	window.onbeforeunload = UnloadConfirm;" + Environment.NewLine);
            sb.Append("	function UnloadConfirm()" + Environment.NewLine);
            sb.Append("	{" + Environment.NewLine);
            sb.Append("		var xx = fConfirm('<%=bPgDirty.ClientID%>','<%=bConfirm.ClientID%>','<%=aNam.ClientID%>','<%=aVal.ClientID%>');" + Environment.NewLine);
            sb.Append("		window.saveerr = window.onerror; window.onerror = function() {return true;}" + Environment.NewLine);
            sb.Append("		setTimeout(function() {window.onerror = window.saveerr}, 10); return xx;" + Environment.NewLine);
            sb.Append("	}" + Environment.NewLine);
            sb.Append("    function ChkExpNow() {if (document.getElementById('<%=bExpNow.ClientID%>').value == 'Y') {window.location = 'Exp.aspx';}}" + Environment.NewLine);
            sb.Append("    Sys.Application.add_load(function () {" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append("        jqTab();" + Environment.NewLine); }
            sb.Append("        ApplyJQueryWidget('<%=aNam.ClientID%>', '<%=aVal.ClientID%>');" + Environment.NewLine);
            sb.Append("    });" + Environment.NewLine);
            sb.Append("    function openButtonSec() {" + Environment.NewLine);
            sb.Append("        if ($('.moreButtonSec').hasClass('hideMoreButtonSec')) { $('.moreButtonSec').removeClass('hideMoreButtonSec');} else { $('.moreButtonSec').addClass('hideMoreButtonSec');};" + Environment.NewLine);
            sb.Append("    }" + Environment.NewLine);
            sb.Append("    $(document).ready(function() {if ( $('.moreButtonSec > div').children().length > 0 ) {$('.MoreBtnCnt').removeClass('hideMoreButtonSec');} else {$('.MoreBtnCnt').addClass('hideMoreButtonSec');}});" + Environment.NewLine);
            sb.Append("    $(document).mouseup(function (e) {" + Environment.NewLine);
            sb.Append("        var container = $('.moreButtonSec');" + Environment.NewLine);
            sb.Append("        if ($(window).width() <= 1024) {" + Environment.NewLine);
            sb.Append("            if (!container.is(e.target) && container.has(e.target).length === 0 && !container.hasClass('hideMoreButtonSec')) { openButtonSec(); }" + Environment.NewLine);
            sb.Append("        }" + Environment.NewLine);
            sb.Append("    });" + Environment.NewLine);
            dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (PopTextBox(drv))
				{
					sb.Append("	function pageLoad() {" + Environment.NewLine);
                    sb.Append("	$(window).resize(function () { try {$(\"#expand\").dialog('option', 'position', { my:'center', at:'center', of:window });} catch(e){}; });" + Environment.NewLine);
                    sb.Append("	$(\"#expand\").dialog({ maxWidth:675, maxHeight:575, width:'80%', height:'80%', modal:true, autoOpen:false, title:\"Text Editor\"," + Environment.NewLine);
					sb.Append("	    buttons: {\"Enter\": function () {SaveExpand();$(this).dialog(\"close\");}}" + Environment.NewLine);
					sb.Append("	    });" + Environment.NewLine);
					sb.Append("	}" + Environment.NewLine);
					sb.Append("	$(\".show-expand-button\").live('click', function () {" + Environment.NewLine);
					sb.Append("	    var title = $(\"#\" + $(this).attr(\"label_id\")).text();" + Environment.NewLine);
					sb.Append("	    var target_textbox = $(this).attr(\"target_id\");" + Environment.NewLine);
					sb.Append("	    $('#<%=cExpandBox.ClientID %>').val($(\"#\" + target_textbox).val());" + Environment.NewLine);
					sb.Append("	    $('#<%=TarBox.ClientID %>').val(target_textbox);" + Environment.NewLine);
					sb.Append("	    $(\"#expand\").dialog(\"option\", \"title\", title);" + Environment.NewLine);
					sb.Append("	    $(\"#expand\").dialog('open');" + Environment.NewLine);
					sb.Append("	    document.getElementById('<%=cExpandBox.ClientID %>').focus();" + Environment.NewLine);
                    sb.Append("	});" + Environment.NewLine);
                    sb.Append("	function SaveExpand() {document.getElementById(document.getElementById('<%=TarBox.ClientID %>').value).value = document.getElementById('<%=cExpandBox.ClientID %>').value; document.getElementById('<%=bPgDirty.ClientID %>').value = 'Y'; ChkPgDirty();}" + Environment.NewLine);
                    sb.Append("$(document).ready(function() {if($('.chkMobile').css('position')=='relative'){ $('.chkMobile').val('isMobile');};});" + Environment.NewLine);
                    break;
				}
			}
            sb.Append("</script>" + Environment.NewLine);
            sb.Append("<asp:PlaceHolder ID=\"FstPHolder\" runat=\"server\" Visible=\"false\" />" + Environment.NewLine);
            sb.Append("<asp:UpdatePanel ID=\"PanelTop\" UpdateMode=\"Conditional\" runat=\"server\"><ContentTemplate>" + Environment.NewLine);
            sb.Append("<asp:ValidationSummary id=\"cValidSummary\" CssClass=\"ValidSumm\" EnableViewState=\"false\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<div id=\"AjaxSpinner\" class=\"AjaxSpinner\" style=\"display:none;\">" + Environment.NewLine);
			sb.Append("	<div style=\"padding:10px;\">" + Environment.NewLine);
			sb.Append("		<img alt=\"\" src=\"images/indicator.gif\" />&nbsp;<asp:Label ID=\"AjaxSpinnerLabel\" Text=\"This may take a moment...\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("	</div>" + Environment.NewLine);
			sb.Append("</div>" + Environment.NewLine);
            sb.Append("<div class=\"r-table BannerGrp\">" + Environment.NewLine);
            sb.Append("<div class=\"r-tr\">" + Environment.NewLine);
            sb.Append("    <div class=\"r-td rc-1-5\">" + Environment.NewLine);
            sb.Append("        <div class=\"BannerNam\"><asp:label id=\"cTitleLabel\" CssClass=\"screen-title\" runat=\"server\" /><input type=\"image\" name=\"cDefaultFocus\" id=\"cClientFocusButton\" src=\"images/Help_x.jpg\" onclick=\"return false;\" style=\"visibility:hidden;\" /></div>" + Environment.NewLine);
            sb.Append("    </div>" + Environment.NewLine);
            sb.Append("    <div class=\"r-td rc-6-12\">" + Environment.NewLine);
            sb.Append("        <div class=\"BannerBtn\">" + Environment.NewLine);
            sb.Append("        <asp:Panel id=\"cButPanel\" runat=\"server\">" + Environment.NewLine);
            sb.Append("            <div class=\"BtnTbl\">" + Environment.NewLine);
            sb.Append("            <div><asp:Button id=\"cEditButton\" onclick=\"cEditButton_Click\" runat=\"server\" CausesValidation=\"true\" Visible=\"false\" /></div>" + Environment.NewLine);
            sb.Append("            <div><asp:Button id=\"cSaveCloseButton\" onclick=\"cSaveCloseButton_Click\" runat=\"server\" CausesValidation=\"true\" Visible=\"false\" /></div>" + Environment.NewLine);
            sb.Append("            <div><asp:Button id=\"cSaveButton\" onclick=\"cSaveButton_Click\" runat=\"server\" Visible=\"<%# CanAct('S') && cSaveButton.Visible %>\" /></div>" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("            <div><asp:Button id=\"cNewSaveButton\" onclick=\"cNewSaveButton_Click\" runat=\"server\" Visible=\"<%# CanAct('S') && cNewSaveButton.Visible %>\" /></div>" + Environment.NewLine);
                sb.Append("            <div><asp:Button id=\"cCopySaveButton\" onclick=\"cCopySaveButton_Click\" runat=\"server\" Visible=\"<%# CanAct('S') && cCopySaveButton.Visible %>\" /></div>" + Environment.NewLine);
                sb.Append("            <div><asp:Button id=\"cNewButton\" onclick=\"cNewButton_Click\" runat=\"server\" CausesValidation=\"true\" Visible=\"<%# CanAct('N') && cNewButton.Visible %>\" /></div>" + Environment.NewLine);
            }
            sb.Append("            <div><asp:image id=\"cPgDirty\" Style=\"visibility:hidden;\" ImageUrl=\"~/images/Xclaim.png\" runat=\"server\" /></div>" + Environment.NewLine);
            sb.Append("            <div class=\"moreButtonSec hideMoreButtonSec\">" + Environment.NewLine);   // Buttons below are in reverse order:
            sb.Append("                <div><asp:Button id=\"cAuditButton\" runat=\"server\" CausesValidation=\"true\" /></div>" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("                <div><asp:Button id=\"cDeleteButton\" onclick=\"cDeleteButton_Click\" runat=\"server\" CausesValidation=\"true\" Visible=\"<%# CanAct('D') && cDeleteButton.Visible %>\" /></div>" + Environment.NewLine);
            }
            sb.Append("                <div><asp:Button id=\"cUndoAllButton\" onclick=\"cUndoAllButton_Click\" runat=\"server\"  CausesValidation=\"true\" Visible=\"<%# CanAct('S') && cUndoAllButton.Visible %>\" /></div>" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("                <div><asp:Button id=\"cCopyButton\" onclick=\"cCopyButton_Click\" runat=\"server\" CausesValidation=\"true\" Visible=\"<%# CanAct('N') && cCopyButton.Visible %>\" /></div>" + Environment.NewLine);
                sb.Append("                <div><asp:Button id=\"cClearButton\" onclick=\"cClearButton_Click\" runat=\"server\" CausesValidation=\"true\" /></div>" + Environment.NewLine);
            }
            sb.Append("                <div><asp:Button id=\"cExpRtfButton\" onclick=\"cExpRtfButton_Click\" runat=\"server\" CausesValidation=\"true\" /></div>" + Environment.NewLine);
            sb.Append("                <div><asp:Button id=\"cExpTxtButton\" onclick=\"cExpTxtButton_Click\" runat=\"server\" CausesValidation=\"true\" /></div>" + Environment.NewLine);
            sb.Append("                <div><asp:Button id=\"cPreviewButton\" onclick=\"cPreviewButton_Click\" runat=\"server\" CausesValidation=\"true\" Visible=\"false\" /></div>" + Environment.NewLine);
            sb.Append("            </div>" + Environment.NewLine);
            sb.Append("            <div class=\"HelpMsgCnt\"><Module:Help id=\"cHelpMsg\" runat=\"server\" /></div>" + Environment.NewLine);
            sb.Append("            <div class=\"MoreBtnCnt\"><asp:Button ID=\"cMoreButton\" OnClientClick=\"openButtonSec(); return false;\" runat=\"server\" /></div>" + Environment.NewLine);
            sb.Append("            <div style=\"clear:both;\"></div>" + Environment.NewLine);
            sb.Append("        </div>" + Environment.NewLine);
			sb.Append("        </asp:Panel>" + Environment.NewLine);
            sb.Append("        </div>" + Environment.NewLine);
            sb.Append("    </div>" + Environment.NewLine);
            sb.Append("</div>" + Environment.NewLine);
            sb.Append("</div>" + Environment.NewLine);
            sb.Append("</ContentTemplate></asp:UpdatePanel>" + Environment.NewLine);
			sb.Append("<asp:UpdatePanel ID=\"PanelUpd\" runat=\"server\">");
            sb.Append("<Triggers>");
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && dvTab != null && dvTab.Count <= 1)
            {
                dv.RowFilter = "MasterTable = 'Y'";
                foreach (DataRowView drv in dv)
                {
                    if (",document,upload,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0)
                    {
                        sb.Append("<asp:PostBackTrigger ControlID=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Upl\" />");
                    }
                }
                dv.RowFilter = string.Empty;
            }
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("<asp:PostBackTrigger ControlID=\"cGridUploadBtn\" /><asp:PostBackTrigger ControlID=\"cBrowseButton\" /><asp:PostBackTrigger ControlID=\"cImportButton\" /><asp:PostBackTrigger ControlID=\"cContinueButton\" />");
			}
            sb.Append("</Triggers>");
            sb.Append("<ContentTemplate>" + Environment.NewLine);
            sb.Append("<asp:PlaceHolder ID=\"MidPHolder\" runat=\"server\" Visible=\"false\" />" + Environment.NewLine);
            sb.Append("<asp:Panel id=\"cCriPanel\" runat=\"server\" wrap=\"false\">" + Environment.NewLine);
            sb.Append("<fieldset class=\"criteria-grp\"><legend>CRITERIA<span><asp:Button id=\"cClearCriButton\" onclick=\"cClearCriButton_Click\" runat=\"server\" CausesValidation=\"true\" /></span></legend>" + Environment.NewLine);
            sb.Append("<div class=\"r-table\">" + Environment.NewLine);
            sb.Append("<div class=\"r-tr\">" + Environment.NewLine);
            sb.Append("    <div class=\"r-td rc-1-8\">" + Environment.NewLine);
            sb.Append("        <div class=\"screen-criteria\">" + Environment.NewLine);
            sb.Append("            <asp:PlaceHolder id=\"cCriteria\" EnableViewState=\"true\" runat=\"server\" />" + Environment.NewLine);
            sb.Append("        </div>" + Environment.NewLine);
            sb.Append("    </div>" + Environment.NewLine);
            sb.Append("    <div class=\"r-td rc-9-12\">" + Environment.NewLine);
            sb.Append("        <div class=\"screen-filter\">" + Environment.NewLine);
            sb.Append("            <asp:Panel id=\"cFilter\" runat=\"server\" visible=\"false\">" + Environment.NewLine);
            sb.Append("            <div class=\"r-table\">" + Environment.NewLine);
            sb.Append("                <div class=\"r-tr\">" + Environment.NewLine);
            sb.Append("                    <div class=\"r-td r-labelR\"><asp:Label id=\"cFilterLabel\" CssClass=\"inp-lbl\" runat=\"server\" /></div>&nbsp;" + Environment.NewLine);
            sb.Append("                    <div class=\"r-td r-content\"><asp:DropDownList id=\"cFilterId\" CssClass=\"inp-ddl\" runat=\"server\" AutoPostBack=\"true\" OnSelectedIndexChanged=\"cFilterId_SelectedIndexChanged\" DataValueField=\"ScreenFilterId\" DataTextField=\"FilterName\" /></div>" + Environment.NewLine);
            sb.Append("                </div>" + Environment.NewLine);
            sb.Append("            </div>" + Environment.NewLine);
            sb.Append("            </asp:Panel>" + Environment.NewLine);
            sb.Append("        </div>" + Environment.NewLine);
            sb.Append("    </div>" + Environment.NewLine);
            sb.Append("</div>" + Environment.NewLine);
            sb.Append("</div>" + Environment.NewLine);
            sb.Append("</fieldset>" + Environment.NewLine);
            sb.Append("</asp:Panel>" + Environment.NewLine);
            sb.Append("<div class=\"r-table\">" + Environment.NewLine);
            sb.Append("<div class=\"r-tr\">" + Environment.NewLine);
            sb.Append("    <div class=\"r-td rc-1-12\">" + Environment.NewLine);
            sb.Append("        <div><asp:label id=\"cGlobalFilter\" cssclass=\"FiltText\" runat=\"server\" visible=\"false\" /></div>" + Environment.NewLine);
            sb.Append("    </div>" + Environment.NewLine);
            sb.Append("</div>" + Environment.NewLine);
            sb.Append("</div>" + Environment.NewLine);
            sb.Append("<div class=\"r-table search-grp\">" + Environment.NewLine);
            sb.Append("<div class=\"r-tr\">" + Environment.NewLine);
            sb.Append("    <div class=\"r-td rc-1-8\">" + Environment.NewLine);
            sb.Append("        <div id=\"cScreenSearch\" class=\"screen-search\" runat=\"server\">" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                dv.RowFilter = "MasterTable = 'Y'";
                foreach (DataRowView drv in dv)
                {
                    if (drv["PrimaryKey"].ToString() == "Y")
                    {
                        //pMKey = drv["ColumnName"].ToString();
                        pMKeyColumn = drv["ColumnName"].ToString() + drv["TableId"].ToString();
                        break;
                    }
                }
                sb.Append("            <div class=\"r-table\">" + Environment.NewLine);
                sb.Append("                <div class=\"r-tr\">" + Environment.NewLine);
                sb.Append("                    <div class=\"r-td r-labelR r-labelM\"><span class='autoCmptPref'>Search:</span></div>" + Environment.NewLine);
                sb.Append("                    <div class=\"r-td r-content\"><rcasp:ComboBox autocomplete=\"off\" id=\"c" + dw["ProgramName"].ToString() + screenId.ToString() + "List\" CssClass=\"inp-ddl\" runat=\"server\"");
                sb.Append(" AutoPostBack=\"true\" OnSelectedIndexChanged=\"c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_SelectedIndexChanged\"");
                sb.Append(" OnTextChanged=\"c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_TextChanged\" OnDDFindClick=\"c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_DDFindClick\"");
                sb.Append(" Mode=\"A\" OnPostBack=\"cbPostBack\" DataValueField=\"" + pMKeyColumn + "\" DataTextField=\"" + pMKeyColumn + "Text\" /></div>" + Environment.NewLine);
                sb.Append("                </div>" + Environment.NewLine);
                sb.Append("            </div>" + Environment.NewLine);
            }
            else
            {
                sb.Append("            &nbsp;" + Environment.NewLine);
            }
            sb.Append("        </div>" + Environment.NewLine);
            sb.Append("    </div>" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("    <div class=\"r-td rc-8-8\">" + Environment.NewLine);
                sb.Append("        <asp:Label ID=\"searchCounter\" CssClass=\"itemTotal\" style='display:none' runat=\"server\"></asp:Label>" + Environment.NewLine);
                sb.Append("    </div>" + Environment.NewLine);
            }
            sb.Append("    <div class=\"r-td rc-9-12\">" + Environment.NewLine);
            sb.Append("        <div id=\"cSystem\" class=\"screen-system\" runat=\"server\" visible=\"false\">" + Environment.NewLine);
            sb.Append("            <div class=\"r-table\">" + Environment.NewLine);
            sb.Append("                <div class=\"r-tr\">" + Environment.NewLine);
            sb.Append("                    <div class=\"r-td r-labelR\"><asp:Label id=\"cSystemLabel\" CssClass=\"inp-lbl\" runat=\"server\" /></div>&nbsp;" + Environment.NewLine);
            sb.Append("                    <div class=\"r-td r-content r-sysid\"><asp:DropDownList id=\"cSystemId\" CssClass=\"inp-ddl\" runat=\"server\" AutoPostBack=\"true\" OnSelectedIndexChanged=\"cSystemId_SelectedIndexChanged\" DataValueField=\"SystemId\" DataTextField=\"SystemName\" /></div>" + Environment.NewLine);
            sb.Append("                </div>" + Environment.NewLine);
            sb.Append("            </div>" + Environment.NewLine);
            sb.Append("        </div>" + Environment.NewLine);
            sb.Append("    </div>" + Environment.NewLine);
            sb.Append("</div>" + Environment.NewLine);
            sb.Append("</div>" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("<asp:Panel id=\"cTabFolder\" runat=\"server\">" + Environment.NewLine);
                if (dvTab != null && dvTab.Count > 1)
				{
                    sb.Append("<input type=\"hidden\" id=\"cCurrentTab\" style=\"display:none\" value=\"cTab" + dvTab[0]["TabFolderId"].ToString() + "\" runat=\"server\"/>" + Environment.NewLine);
                    sb.Append("<ul id=\"tabs\">" + Environment.NewLine);
                    foreach (DataRowView drvTab in dvTab)
                    {
                        sb.Append("    <li><a id=\"cTab" + drvTab["TabFolderId"].ToString() + "\" href=\"#\"" + (drvTab["TabFolderId"].ToString() == dvTab[0]["TabFolderId"].ToString() ? " class=\"current\"" : "") + " name=\"Tab" + drvTab["TabFolderId"].ToString() + "\" runat=\"server\"></a></li>" + Environment.NewLine);
                    }
                    sb.Append("</ul>" + Environment.NewLine);
                    sb.Append("<div id=\"content\">" + Environment.NewLine);
                }
				foreach (DataRowView drvTab in dvTab)
				{
					if (dvTab.Count > 1)
					{
                        sb.Append("<div id=\"Tab" + drvTab["TabFolderId"].ToString() + "\"" + (drvTab["TabFolderId"].ToString() != dvTab[0]["TabFolderId"].ToString() ? " style=\"display:none;\" " : " ") + "runat=\"server\">" + Environment.NewLine);
                        sb.Append("    <asp:UpdatePanel id=\"UpdPanel" + drvTab["TabFolderId"].ToString() + "\" UpdateMode=\"Conditional\" runat=\"server\">");
                        dv.RowFilter = "TabFolderId = " + drvTab["TabFolderId"].ToString();
                        sb.Append("<Triggers>");
                        foreach (DataRowView drv in dv)
			            {
                            if (",document,upload,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0)
                            {
                                sb.Append("<asp:PostBackTrigger ControlID=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Upl\" />");
                            }
			            }
                        dv.RowFilter = string.Empty;
                        sb.Append("</Triggers><ContentTemplate>" + Environment.NewLine);
					}
					MakeObjGrp(ref sb, dv, dvGroupCol, "    ",drvTab["TabFolderId"].ToString(),clientFrwork);
                    if (!string.IsNullOrEmpty(sGrid) && sGridTab == drvTab["TabFolderId"].ToString()) { sb.Append(sGrid); }
                    if (dvTab.Count > 1)
					{
						sb.Append("    </ContentTemplate></asp:UpdatePanel>" + Environment.NewLine);
						sb.Append("</div>" + Environment.NewLine);
					}
				}
                if (dvTab.Count > 1)
                {
                    sb.Append("</div>" + Environment.NewLine);
                    sb.Append("</asp:Panel>" + Environment.NewLine);
                }
			}
            if (!string.IsNullOrEmpty(sGrid) && (string.IsNullOrEmpty(sGridTab) || "I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)) { sb.Append(sGrid); }
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && dvTab != null && dvTab.Count <= 1)
            {
                sb.Append("</asp:Panel>" + Environment.NewLine);
            }
            sb.Append("<asp:label id=\"cFootLabel\" CssClass=\"FootText\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<input id=\"bUseCri\" type=\"hidden\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<input id=\"bPgDirty\" type=\"hidden\" text=\"N\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<input id=\"bConfirm\" type=\"hidden\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<input id=\"aNam\" type=\"hidden\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<input id=\"aVal\" type=\"hidden\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<input id=\"bErrNow\" type=\"hidden\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<input id=\"bInfoNow\" type=\"hidden\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<input id=\"bExpNow\" type=\"hidden\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<input id=\"CtrlToFocus\" type=\"hidden\" runat=\"server\" />" + Environment.NewLine);
			sb.Append("<asp:TextBox ID=\"bViewState\" runat=\"server\" Visible=\"false\" />" + Environment.NewLine);
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (PopTextBox(drv))
				{
                    sb.Append("<div id=\"expand\" style=\"display:none;\">" + Environment.NewLine);
                    sb.Append("	<input id=\"TarBox\" type=\"hidden\" runat=\"server\" />" + Environment.NewLine);
                    sb.Append("    <div id=\"expandbox\"><asp:TextBox ID=\"cExpandBox\" TextMode=\"MultiLine\" CssClass=\"inp-txt\" runat=\"server\" /></div>" + Environment.NewLine);
                    sb.Append("</div>" + Environment.NewLine);
					break;
				}
			}
			sb.Append("<asp:Label ID=\"cMsgContent\" runat=\"server\" style=\"display:none;\" EnableViewState=\"false\"/>" + Environment.NewLine);
			sb.Append("</ContentTemplate></asp:UpdatePanel>" + Environment.NewLine);
            // Add a placeholder for general custom use. Do not delete as older programs may be using this.
            sb.Append("<asp:PlaceHolder ID=\"LstPHolder\" runat=\"server\" Visible=\"false\" />" + Environment.NewLine);
			return sb;
		}

		private StringBuilder MakeAscxCs(DataRow dw, Int32 screenId, string screenTitle, DataView dv, DataView dvTab, DataTable dtLis, DataTable dtDtl, DataView dvWRule, DataView dvCri, DataView dvGroupCol, string appDatabase, string sysDatabase, CurrPrj CPrj, CurrSrc CSrc, string clientFrwork)
		{
			//int ColSize;
			DataView dvs = new DataView(dv.Table.Copy());	// Need dv within dv with different filter.
			int ii = 0;
			string CtrlToSet;
			string cName;
			string sEvent;
			bool bWebRule;
            //bool bListBox;
			int iOffset = 0;
			//DataTable dt = null;
			StringBuilder sb = new StringBuilder();
			StringBuilder ss = new StringBuilder();
			string pMKey = string.Empty;
			string pMKeyColumn = string.Empty;
			string pMKeyIdentity = string.Empty;
			string pMKeySqlName = string.Empty;
			string pMKeyDisplay = string.Empty;
            string pDKey = string.Empty;
            string pDKeyColumn = string.Empty;
			string pDKeyDisplay = string.Empty;
            string pMKeyDByteOle = string.Empty;
            dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (drv["PrimaryKey"].ToString() == "Y")
				{
					if (drv["MasterTable"].ToString() == "Y")
					{
						pMKey = drv["ColumnName"].ToString();
						pMKeyColumn = drv["ColumnName"].ToString() + drv["TableId"].ToString();
						pMKeyIdentity = drv["ColumnIdentity"].ToString();
						pMKeySqlName = drv["DataTypeSqlName"].ToString();
						pMKeyDisplay = drv["DisplayName"].ToString();
                        pMKeyDByteOle = drv["DataTypeDByteOle"].ToString();
					}
					else
					{
                        pDKey = drv["ColumnName"].ToString();
                        pDKeyColumn = drv["ColumnName"].ToString() + drv["TableId"].ToString();
						pDKeyDisplay = drv["DisplayName"].ToString();
					}
				}
			}
			sb.Append("using System;" + Environment.NewLine);
			sb.Append("using System.Data;" + Environment.NewLine);
            sb.Append("using System.Data.OleDb;" + Environment.NewLine);
            //sb.Append("using System.Runtime.Serialization;" + Environment.NewLine);
            sb.Append("using System.Drawing;" + Environment.NewLine);
			sb.Append("using System.IO;" + Environment.NewLine);
            sb.Append("using System.Text;" + Environment.NewLine);
			sb.Append("using System.Web;" + Environment.NewLine);
			sb.Append("using System.Web.UI;" + Environment.NewLine);
			sb.Append("using System.Web.UI.WebControls;" + Environment.NewLine);
			sb.Append("using System.Web.UI.HtmlControls;" + Environment.NewLine);
			sb.Append("using System.Globalization;" + Environment.NewLine);
			sb.Append("using System.Threading;" + Environment.NewLine);
            sb.Append("using System.Threading.Tasks;" + Environment.NewLine);
            sb.Append("using System.Linq;" + Environment.NewLine);
            sb.Append("using System.Diagnostics;" + Environment.NewLine);
            sb.Append("using System.Collections.Generic;" + Environment.NewLine);
            sb.Append("using System.Text.RegularExpressions;" + Environment.NewLine);

			if (clientFrwork != "1") { sb.Append("using AjaxControlToolkit;" + Environment.NewLine); }
            sb.Append("using RO.Facade3;" + Environment.NewLine);
            sb.Append("using RO.Common3;" + Environment.NewLine);
            sb.Append("using RO.Common3.Data;" + Environment.NewLine);
			if (CSrc.SrcSystemId != 3)	// not Admin.
			{
				sb.Append("using " + CPrj.EntityCode + ".UsrRules;" + Environment.NewLine);
                sb.Append("using " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ".Data;" + Environment.NewLine);
            }
			sb.Append("using RO.WebRules;" + Environment.NewLine);
            //sb.Append("using " + CPrj.EntityCode + ".Service" + CSrc.SrcSystemId.ToString() + ";" + Environment.NewLine);
            //if (CSrc.SrcSystemId != 3)	// Admin.
            //{
            //    sb.Append("using RO.Service3;" + Environment.NewLine);
            //}
            MakeDataCs(dw, screenId, dv, sb, pMKeyColumn, CPrj, CSrc);
			sb.Append(Environment.NewLine);
			sb.Append("namespace " + CPrj.EntityCode + ".Web" + Environment.NewLine);
			sb.Append("{" + Environment.NewLine);
			sb.Append("	public partial class " + dw["ProgramName"].ToString() + "Module : RO.Web.ModuleBase" + Environment.NewLine);
			sb.Append("	{" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) 
			{
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dv.RowFilter = "MasterTable <> 'Y'";} else {dv.RowFilter = string.Empty;}
				foreach (DataRowView drv in dv)
				{
					if (drv["DisplayMode"].ToString() == "CheckBoxAll")
					{
						sb.Append("		private bool b" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + " = false;" + Environment.NewLine);
					}
				}
                sb.Append(Environment.NewLine);
				sb.Append("		private const string KEY_lastAddedRow = \"Cache:lastAddedRow" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_lastSortOrd = \"Cache:lastSortOrd" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_lastSortImg = \"Cache:lastSortImg" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_lastSortCol = \"Cache:lastSortCol" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
                sb.Append("		private const string KEY_lastSortExp = \"Cache:lastSortExp" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
                sb.Append("		private const string KEY_lastSortUrl = \"Cache:lastSortUrl" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
                sb.Append("		private const string KEY_lastSortTog = \"Cache:lastSortTog" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
                sb.Append("		private const string KEY_lastImpPwdOvride = \"Cache:lastImpPwdOvride" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_cntImpPwdOvride = \"Cache:cntImpPwdOvride" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_currPageIndex = \"Cache:currPageIndex" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_bHiImpVisible = \"Cache:bHiImpVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_bShImpVisible = \"Cache:bShImpVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_dt" + dw["ProgramName"].ToString() + "Grid = \"Cache:dt" + dw["ProgramName"].ToString() + "Grid\";" + Environment.NewLine);
				sb.Append("		private const string KEY_scrImport = \"Cache:scrImport" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			}
			sb.Append("		private const string KEY_dtScreenHlp = \"Cache:dtScreenHlp" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("		private const string KEY_dtClientRule = \"Cache:dtClientRule" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("		private const string KEY_dtAuthCol = \"Cache:dtAuthCol" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("		private const string KEY_dtAuthRow = \"Cache:dtAuthRow" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("		private const string KEY_dtLabel = \"Cache:dtLabel" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("		private const string KEY_dtCriHlp = \"Cache:dtCriHlp" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
            sb.Append("		private const string KEY_dtScrCri = \"Cache:dtScrCri" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
            sb.Append("		private const string KEY_dsScrCriVal = \"Cache:dsScrCriVal" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
            sb.Append(Environment.NewLine);
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
				{
					sb.Append("		private const string KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + " = \"Cache:dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\";" + Environment.NewLine);
				}
			}
			sb.Append(Environment.NewLine);
			sb.Append("		private const string KEY_dtSystems = \"Cache:dtSystems" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("		private const string KEY_sysConnectionString = \"Cache:sysConnectionString" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) 
			{
				sb.Append("		private const string KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List = \"Cache:dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List\";" + Environment.NewLine);
				sb.Append("		private const string KEY_bNewVisible = \"Cache:bNewVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_bNewSaveVisible = \"Cache:bNewSaveVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_bCopyVisible = \"Cache:bCopyVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_bCopySaveVisible = \"Cache:bCopySaveVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
				sb.Append("		private const string KEY_bDeleteVisible = \"Cache:bDeleteVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			}
			sb.Append("		private const string KEY_bUndoAllVisible = \"Cache:bUndoAllVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("		private const string KEY_bUpdateVisible = \"Cache:bUpdateVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private const string KEY_bClCriVisible = \"Cache:bClCriVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
            //sb.Append("		private const string KEY_bHiCriVisible = \"Cache:bHiCriVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
            //sb.Append("		private const string KEY_bShCriVisible = \"Cache:bShCriVisible" + CSrc.SrcSystemId.ToString() + "_" + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("		private byte LcSystemId;" + Environment.NewLine);
			sb.Append("		private string LcSysConnString;" + Environment.NewLine);
			sb.Append("		private string LcAppConnString;" + Environment.NewLine);
			sb.Append("		private string LcAppDb;" + Environment.NewLine);
			sb.Append("		private string LcDesDb;" + Environment.NewLine);
			sb.Append("		private string LcAppPw;" + Environment.NewLine);
            sb.Append("		protected System.Collections.Generic.Dictionary<string, DataRow> LcAuth;" + Environment.NewLine);
            bWebRule = false;
            foreach (DataRowView drvr in dvWRule)
			{
				if (drvr["EventCode"].ToString() == "FUNPRO")
				{
					bWebRule = true;
					sb.Append(Environment.NewLine);
					sb.Append("		//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append(WrapConditionalWebRule("		", drvr));
				}
			}
            if (bWebRule) 
            { 
                sb.Append("		// *** WebRule End *** //" + Environment.NewLine); 
            } 
            else 
            { 
                sb.Append("		// *** Custom Function/Procedure Web Rule starts here *** //" + Environment.NewLine); 
            }
            //sb.Append(Environment.NewLine);
            //sb.Append("		private AdminWs AdminFacade()" + Environment.NewLine);
            //sb.Append("		{" + Environment.NewLine);
            //sb.Append("		    AdminWs ws = new AdminWs();" + Environment.NewLine);
            //sb.Append("		    ws.Url = Config.WsBaseUrl + \"/AdminWs.asmx\";" + Environment.NewLine);
            //sb.Append("		    ws.Credentials = new System.Net.NetworkCredential(Config.WsUserName, Config.WsPassword, Config.WsDomain);" + Environment.NewLine);
            //sb.Append("		    return ws;" + Environment.NewLine);
            //sb.Append("		}" + Environment.NewLine);
            //sb.Append(Environment.NewLine);
            //sb.Append("		private " + dw["ProgramName"].ToString() + "Ws " + dw["ProgramName"].ToString() + "Facade()" + Environment.NewLine);
            //sb.Append("		{" + Environment.NewLine);
            //sb.Append("		    " + dw["ProgramName"].ToString() + "Ws ws = new " + dw["ProgramName"].ToString() + "Ws();" + Environment.NewLine);
            //sb.Append("		    ws.Url = Config.WsBaseUrl + \"/" + dw["ProgramName"].ToString() + "Ws.asmx\";" + Environment.NewLine);
            //sb.Append("		    ws.Credentials = new System.Net.NetworkCredential(Config.WsUserName, Config.WsPassword, Config.WsDomain);" + Environment.NewLine);
            //sb.Append("		    return ws;" + Environment.NewLine);
            //sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		public " + dw["ProgramName"].ToString() + "Module()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			this.Init += new System.EventHandler(Page_Init);" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		protected void Page_Load(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			Thread.CurrentThread.CurrentCulture = new CultureInfo(base.LUser.Culture);" + Environment.NewLine);
            sb.Append("			string lang2 = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;" + Environment.NewLine);
            sb.Append("			string lang = \"en,zh\".IndexOf(lang2) < 0 ? lang2 : Thread.CurrentThread.CurrentCulture.Name;" + Environment.NewLine);
            sb.Append("			try { ScriptManager.RegisterStartupScript(this, this.GetType(), \"datepicker_i18n\", File.ReadAllText(Request.MapPath(\"~/scripts/i18n/jquery.ui.datepicker-\" + lang + \".js\")), true); } catch { };" + Environment.NewLine);
            sb.Append("			if (!IsPostBack) { Session.Remove(KEY_dtScrCri); }" + Environment.NewLine);
			sb.Append("			int ii = 0; DataView dvCri = GetScrCriteria(); SetCriHolder(ii, dvCri);" + Environment.NewLine);
			sb.Append("			bConfirm.Value = \"Y\";" + Environment.NewLine);
			sb.Append("			// To get around ajax not displaying ErrMsg and InfoMsg; Set them to Y to show immediately:" + Environment.NewLine);
			sb.Append("			bErrNow.Value = \"N\"; bInfoNow.Value = \"N\"; bExpNow.Value = \"N\";" + Environment.NewLine);
            sb.Append("			CtrlToFocus.Value = string.Empty;" + Environment.NewLine);
			sb.Append("			EnableValidators(false);" + Environment.NewLine);
			sb.Append("			if (!IsPostBack)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
            if (dw["AuthRequired"].ToString() == "Y")
            {
                sb.Append("				DataTable dtMenuAccess = (new MenuSystem()).GetMenu(base.LUser.CultureId, " + CSrc.SrcSystemId.ToString() + ", base.LImpr, LcSysConnString, LcAppPw," + screenId.ToString() + ", null, null);" + Environment.NewLine);
                sb.Append("				if (dtMenuAccess.Rows.Count == 0 && !IsCronInvoked())" + Environment.NewLine);
                sb.Append("				{" + Environment.NewLine);
                sb.Append("				    string message = (new AdminSystem()).GetLabel(base.LUser.CultureId, \"cSystem\", \"AccessDeny\", null, null, null);" + Environment.NewLine);
                sb.Append("				    throw new Exception(message);" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
            }
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("				cFind.Attributes.Add(\"OnKeyDown\", \"return EnterKeyCtrl(event,'\" + cFindButton.ClientID + \"')\");" + Environment.NewLine);
                sb.Append("				cPgSize.Attributes.Add(\"OnKeyDown\", \"return EnterKeyCtrl(event,'\" + cPgSizeButton.ClientID + \"')\");" + Environment.NewLine);
                sb.Append("				Session[KEY_lastImpPwdOvride] = 0; Session[KEY_cntImpPwdOvride] = 0; Session[KEY_currPageIndex] = 0;" + Environment.NewLine);
				sb.Append("				Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + "Grid);" + Environment.NewLine);
				sb.Append("				Session.Remove(KEY_lastSortCol);" + Environment.NewLine);
                sb.Append("				Session.Remove(KEY_lastSortExp);" + Environment.NewLine);
                sb.Append("				Session.Remove(KEY_lastSortImg);" + Environment.NewLine);
                sb.Append("				Session.Remove(KEY_lastSortUrl);" + Environment.NewLine);
			}
			if (clientFrwork == "1") { sb.Append("				Session.Remove(\"CtrlToFocus\");" + Environment.NewLine); }
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("				Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List);" + Environment.NewLine);
			}
			sb.Append("				Session.Remove(KEY_dtSystems);" + Environment.NewLine);
			sb.Append("				Session.Remove(KEY_sysConnectionString);" + Environment.NewLine);
            sb.Append("				Session.Remove(KEY_sysConnectionString + \"Pwd\");" + Environment.NewLine);
            sb.Append("				Session.Remove(KEY_dtScreenHlp);" + Environment.NewLine);
			sb.Append("				Session.Remove(KEY_dtClientRule);" + Environment.NewLine);
			sb.Append("				Session.Remove(KEY_dtAuthCol);" + Environment.NewLine);
			sb.Append("				Session.Remove(KEY_dtAuthRow);" + Environment.NewLine);
			sb.Append("				Session.Remove(KEY_dtLabel);" + Environment.NewLine);
			sb.Append("				Session.Remove(KEY_dtCriHlp);" + Environment.NewLine);
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
				{
					sb.Append("				Session.Remove(KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ");" + Environment.NewLine);
				}
			}
			sb.Append("				SetButtonHlp();" + Environment.NewLine);
			sb.Append("				GetSystems();" + Environment.NewLine);
			sb.Append("				SetColumnAuthority();" + Environment.NewLine);
			sb.Append("				GetGlobalFilter();" + Environment.NewLine);
			sb.Append("				GetScreenFilter();" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("				GetPageInfo();" + Environment.NewLine);
			}
			//sb.Append("				if (Request.QueryString[\"typ\"] != null && Request.QueryString[\"typ\"] == \"Y\") {cRetPanel.Visible = true;} else {cRetPanel.Visible = false;}" + Environment.NewLine);
			//sb.Append("				if (Request.QueryString[\"typ\"] != null && Request.QueryString[\"typ\"] == \"N\") {cHideCriButton_Click(sender, new EventArgs());}" + Environment.NewLine);
			sb.Append("				GetCriteria(dvCri);" + Environment.NewLine);
			sb.Append("				DataTable dtHlp = GetScreenHlp();" + Environment.NewLine);
            sb.Append("				cHelpMsg.HelpTitle = dtHlp.Rows[0][\"ScreenTitle\"].ToString(); cHelpMsg.HelpMsg = dtHlp.Rows[0][\"DefaultHlpMsg\"].ToString();" + Environment.NewLine);
			sb.Append("				cFootLabel.Text = dtHlp.Rows[0][\"FootNote\"].ToString();" + Environment.NewLine);
            sb.Append("				if (cFootLabel.Text == string.Empty) { cFootLabel.Visible = false; }" + Environment.NewLine);
            //sb.Append("				if (Request.QueryString[\"cri\"] == \"N\") { cCriPanel.Visible = cShowCriButton.Visible = cClearCriButton.Visible = cHideCriButton.Visible = false; }" + Environment.NewLine);
            sb.Append("				cTitleLabel.Text = dtHlp.Rows[0][\"ScreenTitle\"].ToString();" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && dvTab != null && dvTab.Count > 1)
			{
                sb.Append("				DataTable dt = GetScreenTab();" + Environment.NewLine);
                ii = 0;
				foreach (DataRowView drvTab in dvTab)
				{
                       sb.Append("				cTab" + drvTab["TabFolderId"].ToString() + ".InnerText = dt.Rows[" + ii.ToString() + "][\"TabFolderName\"].ToString();" + Environment.NewLine);
					ii = ii + 1;
				}
			}
            sb.Append("				SetClientRule(null,false);" + Environment.NewLine);
			sb.Append("				IgnoreConfirm(); InitPreserve();" + Environment.NewLine);
            if (dw["MultiDesignDb"].ToString() == "Y")
            {
                sb.Append("				cSystemId_SelectedIndexChanged(null, null);" + Environment.NewLine);
            }
            //if ("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            //{
            //    sb.Append("				if (!string.IsNullOrEmpty(Request.QueryString[\"key\"]) && bUseCri.Value == string.Empty)" + Environment.NewLine);
            //    sb.Append("				{" + Environment.NewLine);
            //    sb.Append("					if (Request.QueryString[\"fnd\"] != null)" + Environment.NewLine);
            //    sb.Append("					{" + Environment.NewLine);
            //    sb.Append("						foreach (ListItem li in cFindFilter.Items) { if (li.Value == Request.QueryString[\"fnd\"].ToString()) { li.Selected = true; } }" + Environment.NewLine);
            //    sb.Append("					}" + Environment.NewLine);
            //    sb.Append("					cFind.Text = Request.QueryString[\"key\"].ToString(); cFindButton_Click(sender, e);" + Environment.NewLine);
            //    sb.Append("				}" + Environment.NewLine);
            //}
			sb.Append("				try" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
            sb.Append("					(new AdminSystem()).LogUsage(base.LUser.UsrId, string.Empty, dtHlp.Rows[0][\"ScreenTitle\"].ToString(), " + screenId.ToString() + ", 0, 0, string.Empty, LcSysConnString, LcAppPw);" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
            sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
            dv.RowFilter = string.Empty;
            foreach (DataRowView drv in dv)
            {
                if (drv["DisplayMode"].ToString().ToLower() == "document")
                {
                    sb.Append("				Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "GV, string.Empty);" + Environment.NewLine);
                }
            }
            bWebRule = false;
            foreach (DataRowView drvr in dvWRule)
            {
                if (drvr["EventCode"].ToString() == "CRICHG")
                {
                    bWebRule = true;
                    sb.Append("				//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append("	" + WrapConditionalWebRule("			", drvr));
                }
            }
            if (bWebRule) { sb.Append("				// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("				// *** Criteria Trigger (before) Web Rule starts here *** //" + Environment.NewLine); }
            sb.Append("				Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, true, null);" + Environment.NewLine);
            sb.Append("				if (cAuditButton.Attributes[\"OnClick\"] == null || cAuditButton.Attributes[\"OnClick\"].IndexOf(\"AdmScrAudit.aspx\") < 0) { cAuditButton.Attributes[\"OnClick\"] += \"SearchLink('AdmScrAudit.aspx?cri0=" + screenId.ToString() + "&typ=N&sys=" + CSrc.SrcSystemId.ToString() + "','','',''); return false;\"; }" + Environment.NewLine);
            foreach (DataRowView drv in dv)
			{
                if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                {
                    //if (drv["DisplayMode"].ToString().ToLower() == "document")
                    //{
                    //    sb.Append("				if (c" + pMKeyColumn + ".Text != string.Empty) { c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Script(); }" + Environment.NewLine);
                    //}
                    //else
                    //{
						sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Script();" + Environment.NewLine);
					//}
				}
			}
            bWebRule = false;
			foreach (DataRowView drvr in dvWRule)
			{
				if (drvr["EventCode"].ToString() == "ENPGLD")
				{
					bWebRule = true;
					sb.Append("				//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
					sb.Append(WrapConditionalWebRule("				", drvr));
				}
			}
            if (bWebRule) { sb.Append("				// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("				// *** Page Load (End of) Web Rule starts here *** //" + Environment.NewLine); }
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("				cBrowse.Attributes.Add(\"OnChange\", \"__doPostBack('\" + cBrowseButton.ClientID.Replace(\"_\", \"$\") + \"','')\");" + Environment.NewLine);
                sb.Append("				DataTable dtLabel = (new AdminSystem()).GetLabels(base.LUser.CultureId, \"cGrid\", null, null, null);" + Environment.NewLine);
                sb.Append("				if (dtLabel != null)" + Environment.NewLine);
                sb.Append("				{" + Environment.NewLine);
                sb.Append("				    cGridFtrLabel.Text = dtLabel.Rows[0][1].ToString();" + Environment.NewLine);
                sb.Append("				    cGridFndLabel.Text = dtLabel.Rows[1][1].ToString();" + Environment.NewLine);
                sb.Append("				    cImpPwdLabel.Text = dtLabel.Rows[2][1].ToString();" + Environment.NewLine);
                sb.Append("				    cImportPwd.ToolTip = dtLabel.Rows[3][1].ToString();" + Environment.NewLine);
                sb.Append("				    cGridWksLabel.Text = dtLabel.Rows[4][1].ToString();" + Environment.NewLine);
                sb.Append("				    cGridStrLabel.Text = dtLabel.Rows[5][1].ToString();" + Environment.NewLine);
                sb.Append("				    cStartRow.ToolTip = dtLabel.Rows[6][1].ToString();" + Environment.NewLine);
                if (dw["ShowGridHead"].ToString() == "N")
                {
                    sb.Append("				    cGridSrtLabel.Text = dtLabel.Rows[7][1].ToString();" + Environment.NewLine);
                }
                sb.Append("				}" + Environment.NewLine);
            }
            sb.Append("			}" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
				sb.Append("			else" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
				sb.Append("				if (dt != null)" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					string sr = ViewState[\"_SortColumn\"] as string;" + Environment.NewLine);
				sb.Append("					if (sr != null) { dt.DefaultView.Sort = sr.ToString(); }" + Environment.NewLine);
				sb.Append("					string rf = ViewState[\"_RowFilter\"] as string;" + Environment.NewLine);
				sb.Append("					if (rf != null) { dt.DefaultView.RowFilter = rf.ToString(); }" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
			}
            sb.Append("			if (IsPostBack && !ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack) {SetClientRule(null,false);};" + Environment.NewLine);
            sb.Append("			if (!IsPostBack)	// Test for Viewstate being lost." + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				bViewState.Text = \"Y\";" + Environment.NewLine);
			sb.Append("				string xx = Session[\"Idle:\" + Request.Url.PathAndQuery] as string;" + Environment.NewLine);
			sb.Append("				if (xx == \"Y\")" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
			sb.Append("					Session.Remove(\"Idle:\" + Request.Url.PathAndQuery);" + Environment.NewLine);
            sb.Append("					bInfoNow.Value = \"Y\"; PreMsgPopup(\"Page has been idled past preset limit and no longer valid, please be notified that it has been reloaded.\");" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			else if (string.IsNullOrEmpty(bViewState.Text))		// Viewstate is lost." + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				Session[\"Idle:\" + Request.Url.PathAndQuery] = \"Y\"; this.Redirect(Request.Url.PathAndQuery);" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            if (dvTab != null && dvTab.Count > 1)
            {
                sb.Append("			if (!string.IsNullOrEmpty(cCurrentTab.Value))" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
                sb.Append("				HtmlControl wcTab = this.FindControl(cCurrentTab.Value.Substring(1)) as HtmlControl;" + Environment.NewLine);
                sb.Append("				wcTab.Style[\"display\"] = \"block\";" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
            }
            sb.Append("			ScriptManager.RegisterStartupScript(this, this.GetType(), \"ScreenLabel\", this.ClientID + \"={\" + string.Join(\",\", (from dr in GetLabel().AsEnumerable() select string.Format(\"{0}: {{msg:'{1}',hint:'{2}'}}\", \"c\" + dr.Field<string>(\"ColumnName\") + (dr.Field<int?>(\"TableId\").ToString()), (dr.Field<string>(\"ErrMessage\") ?? string.Empty).Replace(\"'\", \"\\\\'\").Replace(\"\\r\", \"\\\\r\").Replace(\"\\n\", \"\\\\n\"), (dr.Field<string>(\"TbHint\") ?? string.Empty).Replace(\"'\", \"\\\\'\").Replace(\"\\r\", \"\\\\r\").Replace(\"\\n\", \"\\\\n\"))).ToArray()) + \"};\", true);" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		protected void Page_Init(object sender, EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			bWebRule = false;
			foreach (DataRowView drvr in dvWRule)
			{
				if (drvr["EventCode"].ToString() == "FRPGIN")
				{
					bWebRule = true;
					sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
					sb.Append(WrapConditionalWebRule("			", drvr));
				}
			}
            if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** Page Init (Front of) Web Rule starts here *** //" + Environment.NewLine); }
			sb.Append("			InitializeComponent();" + Environment.NewLine);
			bWebRule = false;
			foreach (DataRowView drvr in dvWRule)
			{
				if (drvr["EventCode"].ToString() == "ENPGIN")
				{
					bWebRule = true;
					sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append(WrapConditionalWebRule("			", drvr));
				}
			}
            if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** Page Init (End of) Web Rule starts here *** //" + Environment.NewLine); }
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		#region Web Form Designer generated code" + Environment.NewLine);
			sb.Append("		/// <summary>" + Environment.NewLine);
			sb.Append("		/// Required method for Designer support - do not modify" + Environment.NewLine);
			sb.Append("		/// the contents of this method with the code editor." + Environment.NewLine);
			sb.Append("		/// </summary>" + Environment.NewLine);
			sb.Append("		private void InitializeComponent()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			CheckAuthentication(true);" + Environment.NewLine);
			sb.Append("			if (LcSysConnString == null)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				SetSystem(" + CSrc.SrcSystemId.ToString() + ");" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("				try" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					DataTable dt;" + Environment.NewLine);
                //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                //sb.Append("						dt = XmlUtils.XmlToDataTable(AdminFacade().GetAuthRow(" + screenId.ToString() + ",base.LImpr.RowAuthoritys,LcSysConnString,LcAppPw));" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
                //sb.Append("					else" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                sb.Append("					dt = (new AdminSystem()).GetAuthRow(" + screenId.ToString() + ",base.LImpr.RowAuthoritys,LcSysConnString,LcAppPw);" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
				sb.Append("					Session[KEY_dtAuthRow] = dt;" + Environment.NewLine);
				sb.Append("					DataRow dr = dt.Rows[0];" + Environment.NewLine);
                sb.Append("					if (!((dr[\"AllowUpd\"].ToString() == \"N\" || dr[\"ViewOnly\"].ToString() == \"G\")");
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append(" && dr[\"AllowAdd\"].ToString() == \"N\""); }
				sb.Append(") && (Request.QueryString[\"enb\"] == null || Request.QueryString[\"enb\"] != \"N\"))" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				sb.Append("						c" + dw["ProgramName"].ToString() + "Grid.PreRender += new EventHandler(c" + dw["ProgramName"].ToString() + "Grid_OnPreRender);" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
                sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			}
			sb.Append("			}" + Environment.NewLine);
            foreach (DataRowView drv in dv)
            {
                //if (!("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y") && (",document,upload,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0 || (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayMode"].ToString().ToLower() == "imagebutton" && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")))
                if (!("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y") && (",document,upload,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0))
                {
                    sb.Append("			cGridUploadBtn.Click += c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Upl_Click;" + Environment.NewLine);
                }
            }
			sb.Append(Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append("		#endregion" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void SetSystem(byte SystemId)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			LcSystemId = SystemId;" + Environment.NewLine);
			sb.Append("			LcSysConnString = base.SysConnectStr(SystemId);" + Environment.NewLine);
			sb.Append("			LcAppConnString = base.AppConnectStr(SystemId);" + Environment.NewLine);
			sb.Append("			LcDesDb = base.DesDb(SystemId);" + Environment.NewLine);
			sb.Append("			LcAppDb = base.AppDb(SystemId);" + Environment.NewLine);
			sb.Append("			LcAppPw = base.AppPwd(SystemId);" + Environment.NewLine);
            sb.Append("			try" + Environment.NewLine);
            sb.Append("			{" + Environment.NewLine);
            //better code but wait for later round of upgrade
            //sb.Append("				DataTable dt = (new RobotSystem()).GetEntityList();" + Environment.NewLine);
            //sb.Append("				if (dt.Rows.Count == 0) throw new Exception(\"Empty Entity Table\");" + Environment.NewLine);
            //sb.Append("				base.CPrj = new CurrPrj(dt.Rows[0]);" + Environment.NewLine);
            sb.Append("				base.CPrj = new CurrPrj(((new RobotSystem()).GetEntityList()).Rows[0]);" + Environment.NewLine);
            sb.Append("				DataRow row = base.SystemsList.Rows.Find(SystemId);" + Environment.NewLine);
            sb.Append("				base.CSrc = new CurrSrc(true, row);" + Environment.NewLine);
            sb.Append("				base.CTar = new CurrTar(true, row);" + Environment.NewLine);
            sb.Append("				if ((Config.DeployType == \"DEV\" || row[\"dbAppDatabase\"].ToString() == base.CPrj.EntityCode + \"View\") && !(base.CPrj.EntityCode != \"RO\" && row[\"SysProgram\"].ToString() == \"Y\") && (new AdminSystem()).IsRegenNeeded(string.Empty," + screenId.ToString() + ",0,0,LcSysConnString,LcAppPw))" + Environment.NewLine);
            sb.Append("				{" + Environment.NewLine);
            sb.Append("					(new GenScreensSystem()).CreateProgram(" + screenId.ToString() + ", \"" + screenTitle + "\", row[\"dbAppDatabase\"].ToString(), base.CPrj, base.CSrc, base.CTar, LcAppConnString, LcAppPw);" + Environment.NewLine);
            sb.Append("					this.Redirect(Request.RawUrl);" + Environment.NewLine);
            sb.Append("				}" + Environment.NewLine);
            sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch (Exception e) { bErrNow.Value = \"Y\"; PreMsgPopup(e.Message); }" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void EnableValidators(bool bEnable)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			foreach (System.Web.UI.WebControls.WebControl va in Page.Validators)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				if (bEnable) {va.Enabled = true;} else {va.Enabled = false;}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            //if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            //{
            //    sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditItem != null)" + Environment.NewLine);
            //    sb.Append("			{" + Environment.NewLine);
            //    sb.Append("			    foreach (Control c in c" + dw["ProgramName"].ToString() + "Grid.EditItem.Controls)" + Environment.NewLine);
            //    sb.Append("			    {" + Environment.NewLine);
            //    sb.Append("			        if (c is BaseValidator) { ((BaseValidator)c).Enabled = bEnable; }" + Environment.NewLine);
            //    sb.Append("			    }" + Environment.NewLine);
            //    sb.Append("			}" + Environment.NewLine);
            //}
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void CheckAuthentication(bool pageLoad)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
            sb.Append("			if (IsCronInvoked())" + Environment.NewLine);
            sb.Append("			{" + Environment.NewLine);
            sb.Append("				AnonymousLogin();" + Environment.NewLine);
            sb.Append("				LCurr.SystemId = " + CSrc.SrcSystemId.ToString() + ";" + Environment.NewLine);
            sb.Append("				LCurr.DbId = " + CSrc.SrcSystemId.ToString() + ";" + Environment.NewLine);
            sb.Append("			}" + Environment.NewLine);
            sb.Append("			else CheckAuthentication(pageLoad, " + (dw["AuthRequired"].ToString() == "N" ? "false" : "true") + ");" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void SetButtonHlp()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			try" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				DataTable dt;" + Environment.NewLine);
            sb.Append("				dt = (new AdminSystem()).GetButtonHlp(" + screenId.ToString() + ",0,0,base.LUser.CultureId,LcSysConnString,LcAppPw);" + Environment.NewLine);
			sb.Append("				if (dt != null && dt.Rows.Count > 0)" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
			sb.Append("					foreach (DataRow dr in dt.Rows)" + Environment.NewLine);
			sb.Append("					{" + Environment.NewLine);
            sb.Append("						if (dr[\"ButtonTypeName\"].ToString() == \"ClearCri\") { cClearCriButton.CssClass = \"ButtonImg ClearCriButtonImg\"; Session[KEY_bClCriVisible] = base.GetBool(dr[\"ButtonVisible\"].ToString()); cClearCriButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
            sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Save\") { cSaveButton.CssClass = \"ButtonImg SaveButtonImg\"; cSaveButton.Text = dr[\"ButtonName\"].ToString(); cSaveButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cSaveButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); Session[KEY_bUpdateVisible] = cSaveButton.Visible; }" + Environment.NewLine);
            sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"ExpTxt\") { cExpTxtButton.CssClass = \"ButtonImg ExpTxtButtonImg\"; cExpTxtButton.Text = dr[\"ButtonName\"].ToString(); cExpTxtButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cExpTxtButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
            sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"ExpRtf\") { cExpRtfButton.CssClass = \"ButtonImg ExpRtfButtonImg\"; cExpRtfButton.Text = dr[\"ButtonName\"].ToString(); cExpRtfButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cExpRtfButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
            sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"UndoAll\") { cUndoAllButton.CssClass = \"ButtonImg UndoAllButtonImg\"; cUndoAllButton.Text = dr[\"ButtonName\"].ToString(); cUndoAllButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cUndoAllButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); Session[KEY_bUndoAllVisible] = cUndoAllButton.Visible; }" + Environment.NewLine);
            sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"More\") { cMoreButton.CssClass = \"ButtonImg MoreButtonImg\"; cMoreButton.Text = dr[\"ButtonName\"].ToString(); cMoreButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cMoreButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
            sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"SaveClose\") { cSaveCloseButton.CssClass = \"ButtonImg SaveCloseButtonImg\"; cSaveCloseButton.Text = dr[\"ButtonName\"].ToString(); cSaveCloseButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cSaveCloseButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
            sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Edit\") { cEditButton.CssClass = \"ButtonImg EditButtonImg\"; cEditButton.Text = dr[\"ButtonName\"].ToString(); cEditButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cEditButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
            sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Preview\") { cPreviewButton.CssClass = \"ButtonImg PreviewButtonImg\"; cPreviewButton.Text = dr[\"ButtonName\"].ToString(); cPreviewButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cPreviewButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
            sb.Append("						if (dr[\"ButtonTypeName\"].ToString() == \"Audit\") { cAuditButton.CssClass = \"ButtonImg AuditButtonImg\"; cAuditButton.Text = dr[\"ButtonName\"].ToString(); cAuditButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cAuditButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("						if (dr[\"ButtonTypeName\"].ToString() == \"Clear\") { cClearButton.CssClass = \"ButtonImg ClearButtonImg\"; cClearButton.Text = dr[\"ButtonName\"].ToString(); cClearButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cClearButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"New\") { cNewButton.CssClass = \"ButtonImg NewButtonImg\"; cNewButton.Text = dr[\"ButtonName\"].ToString(); cNewButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cNewButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); Session[KEY_bNewVisible] = cNewButton.Visible; }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"NewSave\") { cNewSaveButton.CssClass = \"ButtonImg NewSaveButtonImg\"; cNewSaveButton.Text = dr[\"ButtonName\"].ToString(); cNewSaveButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cNewSaveButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); Session[KEY_bNewSaveVisible] = cNewSaveButton.Visible; }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Copy\") { cCopyButton.CssClass = \"ButtonImg CopyButtonImg\"; cCopyButton.Text = dr[\"ButtonName\"].ToString(); cCopyButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cCopyButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); Session[KEY_bCopyVisible] = cCopyButton.Visible;}" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"CopySave\") { cCopySaveButton.CssClass = \"ButtonImg CopySaveButtonImg\"; cCopySaveButton.Text = dr[\"ButtonName\"].ToString(); cCopySaveButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cCopySaveButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); Session[KEY_bCopySaveVisible] = cCopySaveButton.Visible;}" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Delete\") { cDeleteButton.CssClass = \"ButtonImg DeleteButtonImg\"; cDeleteButton.Text = dr[\"ButtonName\"].ToString(); cDeleteButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cDeleteButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); Session[KEY_bDeleteVisible] = cDeleteButton.Visible;}" + Environment.NewLine);
			}
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("						if (dr[\"ButtonTypeName\"].ToString() == \"InsRow\") { cInsRowButton.CssClass = \"ButtonImg InsRowButtonImg\"; cInsRowButton.Text = \"ADD\"; cInsRowButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cInsRowButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"PgSize\") { cPgSizeButton.CssClass = \"ButtonImg PgSizeButtonImg\"; cPgSizeButton.Text = string.Empty; cPgSizeButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cPgSizeButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); cPgSize.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"First\") { cFirstButton.CssClass = \"ButtonImg FirstButtonImg\"; cFirstButton.Text = string.Empty; cFirstButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cFirstButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Prev\") { cPrevButton.CssClass = \"ButtonImg PrevButtonImg\"; cPrevButton.Text = string.Empty; cPrevButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cPrevButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Next\") { cNextButton.CssClass = \"ButtonImg NextButtonImg\"; cNextButton.Text = string.Empty; cNextButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cNextButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Last\") { cLastButton.CssClass = \"ButtonImg LastButtonImg\"; cLastButton.Text = string.Empty; cLastButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cLastButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Find\") { cFindButton.CssClass = \"ButtonImg FindButtonImg\"; cFindButton.Text = string.Empty; cFindButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cFindButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); cFind.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Import\") { cImportButton.CssClass = \"ButtonImg ImportButtonImg\"; cImportButton.Text = string.Empty; cImportButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cImportButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"Continue\") { cContinueButton.CssClass = \"ButtonImg ContinueButtonImg\"; cContinueButton.Text = string.Empty; cContinueButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cContinueButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"HideImp\") { cHideImpButton.CssClass = \"ButtonImg HideImpButtonImg\"; cHideImpButton.Text = string.Empty; cHideImpButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cHideImpButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); Session[KEY_bHiImpVisible] = base.GetBool(dr[\"ButtonVisible\"].ToString()); cHideImpButton.Visible = false; }" + Environment.NewLine);
                sb.Append("						else if (dr[\"ButtonTypeName\"].ToString() == \"ShowImp\") { cShowImpButton.CssClass = \"ButtonImg ShowImpButtonImg\"; cShowImpButton.Text = string.Empty; cShowImpButton.Visible = base.GetBool(dr[\"ButtonVisible\"].ToString()); cShowImpButton.ToolTip = dr[\"ButtonToolTip\"].ToString(); Session[KEY_bShImpVisible] = cShowImpButton.Visible; }" + Environment.NewLine);
			}
			sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private DataTable GetClientRule()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			DataTable dtRul = (DataTable)Session[KEY_dtClientRule];" + Environment.NewLine);
			sb.Append("			if (dtRul == null)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				CheckAuthentication(false);" + Environment.NewLine);
			sb.Append("				try" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
            //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						dtRul = XmlUtils.XmlToDataTable(AdminFacade().GetClientRule(" + screenId.ToString() + ",0,base.LUser.CultureId,LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            sb.Append("					dtRul = (new AdminSystem()).GetClientRule(" + screenId.ToString() + ",0,base.LUser.CultureId,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
            sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("				Session[KEY_dtClientRule] = dtRul;" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			return dtRul;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		private void SetClientRule(ListViewDataItem ee, bool isEditItem)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
			sb.Append("			DataView dvRul = new DataView(GetClientRule());" + Environment.NewLine);
			if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("			if (ee != null) {dvRul.RowFilter = \"MasterTable = 'N'\";} else {dvRul.RowFilter = \"MasterTable <> 'N'\";}" + Environment.NewLine);
			}
			//if ("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			//{
                //sb.Append("			if (ee != null) {dvRul.RowFilter = \"MasterTable = 'Y'\";} else {dvRul.RowFilter = \"MasterTable <> 'Y'\";}" + Environment.NewLine);
            //}
			sb.Append("			if (dvRul.Count > 0)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				WebControl cc = null;" + Environment.NewLine);
			sb.Append("				string srp = string.Empty;" + Environment.NewLine);
			sb.Append("				string sn = string.Empty;" + Environment.NewLine);
			sb.Append("				string st = string.Empty;" + Environment.NewLine);
            sb.Append("				string sg = string.Empty;" + Environment.NewLine);
            sb.Append("				int ii = 0;" + Environment.NewLine);
            sb.Append("				int jj = 0;" + Environment.NewLine);
            sb.Append("				Regex missing = new Regex(\"@[0-9]+@\");" + Environment.NewLine);
            sb.Append("				string lang2 = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;" + Environment.NewLine);
            sb.Append("				string lang = \"en,zh\".IndexOf(lang2) < 0 ? lang2 : Thread.CurrentThread.CurrentCulture.Name;" + Environment.NewLine);
            sb.Append("				foreach (DataRowView drv in dvRul)" + Environment.NewLine);
            sb.Append("				{" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("					if (ee == null || drv[\"ScriptEvent\"].ToString().Substring(0,2).ToLower() != \"on\" || (c" + dw["ProgramName"].ToString() + "Grid.EditIndex > -1 && GetDataItemIndex(c" + dw["ProgramName"].ToString() + "Grid.EditIndex) == ee.DataItemIndex))" + Environment.NewLine);
			}
			else {sb.Append("					if (ee == null)" + Environment.NewLine);}
			sb.Append("					{" + Environment.NewLine);
			sb.Append("						srp = drv[\"ScriptName\"].ToString();" + Environment.NewLine);
            sb.Append("						srp = srp.Replace(\"@cLang@\", \"\\'\" + lang + \"\\'\");" + Environment.NewLine);
            sb.Append("						if (drv[\"ParamName\"].ToString() != string.Empty)" + Environment.NewLine);
            sb.Append("						{" + Environment.NewLine);
			sb.Append("							StringBuilder sbName =  new StringBuilder();" + Environment.NewLine);
			sb.Append("							StringBuilder sbType =  new StringBuilder();" + Environment.NewLine);
            sb.Append("							StringBuilder sbInGrid =  new StringBuilder();" + Environment.NewLine);
            sb.Append("							sbName.Append(drv[\"ParamName\"].ToString().Trim());" + Environment.NewLine);
            sb.Append("							sbType.Append(drv[\"ParamType\"].ToString().Trim());" + Environment.NewLine);
            sb.Append("							sbInGrid.Append(drv[\"ParamInGrid\"].ToString().Trim());" + Environment.NewLine);
            sb.Append("							ii = 0;" + Environment.NewLine);
            sb.Append("							while (sbName.Length > 0)" + Environment.NewLine);
			sb.Append("							{" + Environment.NewLine);
            sb.Append("								sn = Utils.PopFirstWord(sbName,(char)44); st = Utils.PopFirstWord(sbType,(char)44);sg = Utils.PopFirstWord(sbInGrid,(char)44);" + Environment.NewLine);
            sb.Append("								if (ee != null && sg == \"Y\")" + Environment.NewLine);
            sb.Append("								{" + Environment.NewLine);
            sb.Append("									if (st.ToLower() == \"combobox\" && isEditItem) {srp = srp.Replace(\"@\" + ii.ToString() + \"@\",\"'\"+((RoboCoder.WebControls.ComboBox)ee.FindControl(sn)).KeyID+\"'\");} else {srp = srp.Replace(\"@\" + ii.ToString() + \"@\",\"'\"+((WebControl)ee.FindControl(sn + (!isEditItem ? \"l\" : \"\"))).ClientID+\"'\");}" + Environment.NewLine);
            sb.Append("								}" + Environment.NewLine);
			sb.Append("								else" + Environment.NewLine);
			sb.Append("								{" + Environment.NewLine);
            sb.Append("									if (st.ToLower() == \"combobox\") {srp = srp.Replace(\"@\" + ii.ToString() + \"@\",\"'\"+((RoboCoder.WebControls.ComboBox)this.FindControl(sn)).KeyID+\"'\");} else {srp = srp.Replace(\"@\" + ii.ToString() + \"@\",\"'\"+((WebControl)this.FindControl(sn)).ClientID+\"'\");}" + Environment.NewLine);
            sb.Append("								}" + Environment.NewLine);
			sb.Append("								ii = ii + 1;" + Environment.NewLine);
			sb.Append("							}" + Environment.NewLine);
			sb.Append("						}" + Environment.NewLine);
            sb.Append("						if (drv[\"ScriptEvent\"].ToString() == \"js\")" + Environment.NewLine);
            sb.Append("						{" + Environment.NewLine);
            sb.Append("							ScriptManager.RegisterStartupScript(this, this.GetType(), drv[\"ColName\"].ToString() + \"_\" + drv[\"ScriptName\"].ToString() + jj.ToString(),\"<script>\"+ drv[\"ClientRuleProg\"].ToString() + srp + \"</script>\", false);" + Environment.NewLine);
            sb.Append("						}" + Environment.NewLine);
            sb.Append("						else if (drv[\"ScriptEvent\"].ToString() == \"css\")" + Environment.NewLine);
            sb.Append("						{" + Environment.NewLine);
            sb.Append("							ScriptManager.RegisterClientScriptBlock(this, this.GetType(), drv[\"ColName\"].ToString() + \"_\" + drv[\"ScriptName\"].ToString() + jj.ToString(),\"<style>\"+ drv[\"ClientRuleProg\"].ToString() + \"</style>\", false);" + Environment.NewLine);
            sb.Append("						}" + Environment.NewLine);
            sb.Append("						else if (drv[\"ScriptEvent\"].ToString() == \"css_link\")" + Environment.NewLine);
            sb.Append("						{" + Environment.NewLine);
            sb.Append("							ScriptManager.RegisterClientScriptBlock(this, this.GetType(), drv[\"ColName\"].ToString() + \"_\" + drv[\"ScriptName\"].ToString() + jj.ToString(),\"<link  rel='stylesheet' type='text/css' href='\"+ drv[\"ClientRuleProg\"].ToString() + \"' />\", false);" + Environment.NewLine);
            sb.Append("						}" + Environment.NewLine);
            sb.Append("						else if (drv[\"ScriptEvent\"].ToString() == \"js_link\")" + Environment.NewLine);
            sb.Append("						{" + Environment.NewLine);
            sb.Append("							ScriptManager.RegisterClientScriptBlock(this, this.GetType(), drv[\"ColName\"].ToString() + \"_\" + drv[\"ScriptName\"].ToString() + jj.ToString(),\"<script type='text/javascript' src='\"+ drv[\"ClientRuleProg\"].ToString() + \"'></script>\", false);" + Environment.NewLine);
            sb.Append("						}" + Environment.NewLine);
            sb.Append("						else" + Environment.NewLine);
            sb.Append("						{" + Environment.NewLine);
            sb.Append("							srp = missing.Replace(srp, \"''\");" + Environment.NewLine);
            sb.Append("							string scriptEvent = drv[\"ScriptEvent\"].ToString().TrimStart(new char[]{'_'});" + Environment.NewLine);
            sb.Append("							if (ee != null) {cc = ee.FindControl(drv[\"ColName\"].ToString()) as WebControl;} else {cc = this.FindControl(drv[\"ColName\"].ToString()) as WebControl;}" + Environment.NewLine);
            sb.Append("							if (cc != null && (cc.Attributes[scriptEvent] == null || cc.Attributes[scriptEvent].IndexOf(srp) < 0)) {cc.Attributes[scriptEvent] += srp;}" + Environment.NewLine);
            sb.Append("							if (ee != null && drv[\"ScriptEvent\"].ToString().Substring(0,2).ToLower() != \"on\")" + Environment.NewLine);
            sb.Append("							{" + Environment.NewLine);
            sb.Append("								cc = ee.FindControl(drv[\"ColName\"].ToString() + \"l\") as WebControl;" + Environment.NewLine);
            sb.Append("								if (cc != null && (cc.Attributes[scriptEvent] == null || cc.Attributes[scriptEvent].IndexOf(srp) < 0)) {cc.Attributes[scriptEvent] += srp;}" + Environment.NewLine);
            sb.Append("							}" + Environment.NewLine);
            sb.Append("						}" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					jj = jj + 1;" + Environment.NewLine);
            sb.Append("				}" + Environment.NewLine);
            sb.Append("			}" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private DataTable GetScreenCriHlp()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			DataTable dtCriHlp = (DataTable)Session[KEY_dtCriHlp];" + Environment.NewLine);
			sb.Append("			if (dtCriHlp == null)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				CheckAuthentication(false);" + Environment.NewLine);
			sb.Append("				try" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
            //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						dtCriHlp = XmlUtils.XmlToDataTable(AdminFacade().GetScreenCriHlp(" + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            sb.Append("					dtCriHlp = (new AdminSystem()).GetScreenCriHlp(" + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
            sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("				Session[KEY_dtCriHlp] = dtCriHlp;" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			return dtCriHlp;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private DataTable GetScreenHlp()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			DataTable dtHlp = (DataTable)Session[KEY_dtScreenHlp];" + Environment.NewLine);
			sb.Append("			if (dtHlp == null)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				CheckAuthentication(false);" + Environment.NewLine);
			sb.Append("				try" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
            //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						dtHlp = XmlUtils.XmlToDataTable(AdminFacade().GetScreenHlp(" + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            sb.Append("					dtHlp = (new AdminSystem()).GetScreenHlp(" + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
            sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("				Session[KEY_dtScreenHlp] = dtHlp;" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			return dtHlp;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void GetGlobalFilter()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			try" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				DataTable dt;" + Environment.NewLine);
            //sb.Append("				if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("				{" + Environment.NewLine);
            //sb.Append("					dt = XmlUtils.XmlToDataTable(AdminFacade().GetGlobalFilter(base.LUser.UsrId," + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("				}" + Environment.NewLine);
            //sb.Append("				else" + Environment.NewLine);
            //sb.Append("				{" + Environment.NewLine);
            sb.Append("				dt = (new AdminSystem()).GetGlobalFilter(base.LUser.UsrId," + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("				}" + Environment.NewLine);
			sb.Append("				if (dt != null && dt.Rows.Count > 0)" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
			sb.Append("					cGlobalFilter.Text = dt.Rows[0][\"FilterDesc\"].ToString();" + Environment.NewLine);
			sb.Append("					cGlobalFilter.Visible = true;" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void GetScreenFilter()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			try" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			//sb.Append("				DataTable dt;" + Environment.NewLine);
            //sb.Append("				if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("				{" + Environment.NewLine);
            //sb.Append("					dt = XmlUtils.XmlToDataTable(AdminFacade().GetScreenFilter(" + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("				}" + Environment.NewLine);
            //sb.Append("				else" + Environment.NewLine);
            //sb.Append("				{" + Environment.NewLine);
            sb.Append("				DataTable dt = (new AdminSystem()).GetScreenFilter(" + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("				}" + Environment.NewLine);
			sb.Append("				if (dt != null)" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
			sb.Append("					cFilterId.DataSource = dt;" + Environment.NewLine);
			sb.Append("					cFilterId.DataBind();" + Environment.NewLine);
			sb.Append("					if (cFilterId.Items.Count > 0)" + Environment.NewLine);
			sb.Append("					{" + Environment.NewLine);
			sb.Append("						if (Request.QueryString[\"ftr\"] != null) {cFilterId.Items.FindByValue(Request.QueryString[\"ftr\"]).Selected = true;} else {cFilterId.Items[0].Selected = true;}" + Environment.NewLine);
            //sb.Append("						if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            //sb.Append("							cFilterLabel.Text = AdminFacade().GetLabel(base.LUser.CultureId, \"QFilter\", \"QFilter\", null, null, null);" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
            //sb.Append("						else" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            sb.Append("						cFilterLabel.Text = (new AdminSystem()).GetLabel(base.LUser.CultureId, \"QFilter\", \"QFilter\", null, null, null);" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
			sb.Append("						cFilter.Visible = true;" + Environment.NewLine);
			sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void GetSystems()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			Session[KEY_sysConnectionString] = LcSysConnString;" + Environment.NewLine);
            sb.Append("			Session[KEY_sysConnectionString + \"Pwd\"] = LcAppPw;" + Environment.NewLine);
            if (dw["SysProgram"].ToString() == "Y" && dw["MultiDesignDb"].ToString() == "Y")
			{
				sb.Append("			DataTable dtSystems = base.SystemsList;" + Environment.NewLine);
				sb.Append("			if (dtSystems != null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				Session[KEY_dtSystems] = dtSystems;" + Environment.NewLine);
				sb.Append("				cSystemId.DataSource = dtSystems;" + Environment.NewLine);
				sb.Append("				cSystemId.DataBind();" + Environment.NewLine);
				sb.Append("				if (cSystemId.Items.Count > 1)" + Environment.NewLine);    // Only make sense if more than one system.
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					if (Request.QueryString[\"sys\"] != null) {cSystemId.Items.FindByValue(Request.QueryString[\"sys\"]).Selected = true;}" + Environment.NewLine);
				sb.Append("					else" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				sb.Append("						try { cSystemId.Items.FindByValue(base.LCurr.DbId.ToString()).Selected = true; }" + Environment.NewLine);
				sb.Append("						catch {cSystemId.Items[0].Selected = true;}" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("					base.LCurr.DbId = byte.Parse(cSystemId.SelectedValue);" + Environment.NewLine);
				sb.Append("					Session[KEY_sysConnectionString] = Config.GetConnStr(dtSystems.Rows[cSystemId.SelectedIndex][\"dbAppProvider\"].ToString(), dtSystems.Rows[cSystemId.SelectedIndex][\"ServerName\"].ToString(), dtSystems.Rows[cSystemId.SelectedIndex][\"dbDesDatabase\"].ToString(), \"\", dtSystems.Rows[cSystemId.SelectedIndex][\"dbAppUserId\"].ToString());" + Environment.NewLine);
                sb.Append("					Session[KEY_sysConnectionString + \"Pwd\"] = base.AppPwd(base.LCurr.DbId);" + Environment.NewLine);
                //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                //sb.Append("						cSystemLabel.Text = AdminFacade().GetLabel(base.LUser.CultureId, \"cSystem\", \"Label\", null, null, null);" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
                //sb.Append("					else" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                sb.Append("					cSystemLabel.Text = (new AdminSystem()).GetLabel(base.LUser.CultureId, \"cSystem\", \"Label\", null, null, null);" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
                sb.Append("					cSystem.Visible = true;" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
			}
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		protected string ColumnWatermark(int idx)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			return GetLabel().Rows[idx][\"tbHint\"].ToString();" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            sb.Append("		protected string ColumnHeaderText(int idx)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			return (GetLabel().Rows[idx][\"RequiredValid\"].ToString() == \"Y\" ? Config.MandatoryChar : string.Empty)  + GetLabel().Rows[idx][\"ColumnHeader\"].ToString();" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            sb.Append("		protected string ColumnToolTip(int idx)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			return GetLabel().Rows[idx][\"ToolTip\"].ToString();" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            sb.Append("		protected bool GridColumnVisible(int idx)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			return GetAuthCol().Rows[idx][\"ColVisible\"].ToString()==\"Y\";" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            sb.Append("		protected bool GridColumnEnable(int idx)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			return GetAuthCol().Rows[idx][\"ColReadOnly\"].ToString()==\"N\";" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            sb.Append("		private DataTable GetLabel()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			DataTable dt = (DataTable)Session[KEY_dtLabel];" + Environment.NewLine);
			sb.Append("			if (dt == null)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				try" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
            //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						dt = XmlUtils.XmlToDataTable(AdminFacade().GetScreenLabel(" + screenId.ToString() + ",base.LUser.CultureId,XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr),LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            sb.Append("					dt = (new AdminSystem()).GetScreenLabel(" + screenId.ToString() + ",base.LUser.CultureId,base.LImpr,base.LCurr,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
            sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("				Session[KEY_dtLabel] = dt;" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			return dt;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private DataTable GetAuthCol()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			DataTable dt = (DataTable)Session[KEY_dtAuthCol];" + Environment.NewLine);
			sb.Append("			if (dt == null)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				try" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
            //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						dt = XmlUtils.XmlToDataTable(AdminFacade().GetAuthCol(" + screenId.ToString() + ",XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr),LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            sb.Append("					dt = (new AdminSystem()).GetAuthCol(" + screenId.ToString() + ",base.LImpr,base.LCurr,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
            sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("				Session[KEY_dtAuthCol] = dt;" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			return dt;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		protected DataTable GetAuthRow()" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
			sb.Append("			DataTable dt = (DataTable)Session[KEY_dtAuthRow];" + Environment.NewLine);
			sb.Append("			if (dt == null)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				try" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
            //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						dt = XmlUtils.XmlToDataTable(AdminFacade().GetAuthRow(" + screenId.ToString() + ",base.LImpr.RowAuthoritys,LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            sb.Append("					dt = (new AdminSystem()).GetAuthRow(" + screenId.ToString() + ",base.LImpr.RowAuthoritys,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
            sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("				Session[KEY_dtAuthRow] = dt;" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			return dt;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void getReport(string eExport)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			try" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				StringBuilder sb = new StringBuilder();" + Environment.NewLine);
			sb.Append("				CheckAuthentication(false);" + Environment.NewLine);
			sb.Append("				DataView dv = null;" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("				int filterId = 0; if (Utils.IsInt(cFilterId.SelectedValue)) { filterId = int.Parse(cFilterId.SelectedValue); }" + Environment.NewLine);
				sb.Append("				try" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
                //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                //sb.Append("						try {dv = new DataView(XmlUtils.XmlToDataTable(" + dw["ProgramName"].ToString() + "Facade().GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "(\"Y\"," + screenId.ToString() + Robot.GetCnCall(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,XmlUtils.DataViewToXml(GetScrCriteria()),XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr),XmlUtils.DataSetToXml(UpdCriteria(false)))));}" + Environment.NewLine);
                //sb.Append("						catch {dv = new DataView(XmlUtils.XmlToDataTable(" + dw["ProgramName"].ToString() + "Facade().GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "(\"N\"," + screenId.ToString() + Robot.GetCnCall(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,XmlUtils.DataViewToXml(GetScrCriteria()),XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr),XmlUtils.DataSetToXml(UpdCriteria(false)))));}" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
                //sb.Append("					else" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                sb.Append("					try {dv = new DataView((new AdminSystem()).GetExp(" + screenId.ToString() + ",\"GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "\",\"Y\"" + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false)));}" + Environment.NewLine);
                sb.Append("					catch {dv = new DataView((new AdminSystem()).GetExp(" + screenId.ToString() + ",\"GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "\",\"N\"" + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false)));}" + Environment.NewLine);
                //sb.Append("						try {dv = new DataView((new " + dw["ProgramName"].ToString() + "System()).GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "(\"Y\"," + screenId.ToString() + Robot.GetCnCall(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false)));}" + Environment.NewLine);
                //sb.Append("						catch {dv = new DataView((new " + dw["ProgramName"].ToString() + "System()).GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "(\"N\"," + screenId.ToString() + Robot.GetCnCall(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false)));}" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
                sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
			}
			else
			{
				sb.Append("				try {dv = ((DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid]).DefaultView;}" + Environment.NewLine);
                sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
			}
			sb.Append("				if (eExport == \"TXT\")" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
			sb.Append("					DataTable dtAu;" + Environment.NewLine);
            //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						dtAu = XmlUtils.XmlToDataTable(AdminFacade().GetAuthExp(" + screenId.ToString() + ",base.LUser.CultureId,XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr),LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            sb.Append("					dtAu = (new AdminSystem()).GetAuthExp(" + screenId.ToString() + ",base.LUser.CultureId,base.LImpr,base.LCurr,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("					if (dtAu != null)" + Environment.NewLine);
			sb.Append("					{" + Environment.NewLine);
			ii = 0;
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (",Password,Image,drilldown,popup,Button,ImageButton,PlaceHolder,Document,".IndexOf("," + drv["DisplayMode"].ToString() + ",") < 0 && drv["ColumnId"].ToString() != string.Empty && drv["DataTypeSqlName"].ToString().IndexOf("Text") < 0)
				{
					sb.Append("						if (dtAu.Rows[" + ii.ToString() + "][\"ColExport\"].ToString() == \"Y\") {sb.Append(dtAu.Rows[" + ii.ToString() + "][\"ColumnHeader\"].ToString() + (char)9");
					// Listbox is currently multiple selection and may return duplicate rows:
					if (",ComboBox,DropDownList,RadioButtonList,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
					{
						sb.Append(" + dtAu.Rows[" + ii.ToString() + "][\"ColumnHeader\"].ToString() + \" Text\" + (char)9");
					}
					sb.Append(");}" + Environment.NewLine);
				}
				ii = ii + 1;
			}
			sb.Append("						sb.Append(Environment.NewLine);" + Environment.NewLine);
			sb.Append("					}" + Environment.NewLine);
			sb.Append("					foreach (DataRowView drv in dv)" + Environment.NewLine);
			sb.Append("					{" + Environment.NewLine);
			ii = 0;
			foreach (DataRowView drv in dv)
			{
				if (",Password,Image,drilldown,popup,Button,ImageButton,PlaceHolder,Document,".IndexOf("," + drv["DisplayMode"].ToString() + ",") < 0 && drv["ColumnId"].ToString() != string.Empty && drv["DataTypeSqlName"].ToString().IndexOf("Text") < 0)
				{
					sb.Append("						if (dtAu.Rows[" + ii.ToString() + "][\"ColExport\"].ToString() == \"Y\") {sb.Append(");
					if (drv["DataTypeSysName"].ToString() == "String") {sb.Append("\"\\\"\" + ");}
                    if (drv["DisplayMode"].ToString().ToLower() == "currency")
                    {
                        sb.Append("base.fxCurrency(drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()");
                        sb.Append(string.IsNullOrEmpty(drv["DdlKeyColumnName"].ToString()) ? ",base.LUser.Culture" : ",drv[\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "\"].ToString()");
                        sb.Append(string.IsNullOrEmpty(drv["DdlRefColumnName"].ToString()) ? ",base.LUser.Culture)" : ",drv[\"" + drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString() + "\"].ToString())");
                    }
                    else
                    {
                        sb.Append(Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), true).Replace("LongDate", "ShortDate") + "drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()");
                        if (drv["DataTypeSysName"].ToString() == "String") { sb.Append(".Replace(\"\\\"\",\"\\\"\\\"\")"); }
                        sb.Append(Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), string.Empty, false));
                    }
					if (drv["DataTypeSysName"].ToString() == "String") {sb.Append(" + \"\\\"\"");}
					sb.Append(" + (char)9");
					// Listbox and DataGrid are currently multiple selection and may return duplicate rows:
					if (",ComboBox,DropDownList,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
						sb.Append(" + ");
						if (drv["DataTypeSysName"].ToString() == "String") {sb.Append("\"\\\"\" + ");}
                        sb.Append(Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), true).Replace("LongDate", "ShortDate") + "drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"].ToString()");
                        if (drv["DataTypeSysName"].ToString() == "String") { sb.Append(".Replace(\"\\\"\",\"\\\"\\\"\")"); }
                        sb.Append(Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), string.Empty, false));
						if (drv["DataTypeSysName"].ToString() == "String") {sb.Append(" + \"\\\"\"");}
						sb.Append(" + (char)9");
					}
					sb.Append(");}" + Environment.NewLine);
				}
				ii = ii + 1;
			}
			sb.Append("						sb.Append(Environment.NewLine);" + Environment.NewLine);
			sb.Append("					}" + Environment.NewLine);
            sb.Append("					bExpNow.Value = \"Y\"; Session[\"ExportFnm\"] = \"" + dw["ProgramName"].ToString() + ".csv\"; Session[\"ExportStr\"] = (Config.ExportExcelCSV ? \"sep=\\t\\n\": \"\") + sb.Replace(\"\\r\\n\",\"\\n\");" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
			sb.Append("				else if (eExport == \"RTF\")" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
			string sTemplate;
			StreamReader sr = new StreamReader(Config.ClientTierPath + @"templates\ScreenTmpl.rtf");
			try	{sTemplate = sr.ReadToEnd();} finally {sr.Close();}
			sb.Append("					sb.Append(@\"" + sTemplate + "\");" + Environment.NewLine);
			sb.Append("					sb.Replace(\"[[TitleLabel]]\", cTitleLabel.Text);" + Environment.NewLine);
			sb.Append("					sb.Replace(\"[[GlobalFilter]]\", cGlobalFilter.Text);" + Environment.NewLine);
			sb.Append("					sb.Replace(\"[[Grid]]\", GetRtfGrid(dv));" + Environment.NewLine);
			sb.Append("					bExpNow.Value = \"Y\"; Session[\"ExportFnm\"] = \"" + dw["ProgramName"].ToString() + ".rtf\"; Session[\"ExportStr\"] = sb;" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			string sLine = @"\r\n";
			string sBoldBeg = @"\b";
			string sBoldEnd = @"\b0";
			string s1 = @"\trowd \irow0\irowband0\lastrow \ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10 ";
			string s2 = @"\trftsWidth1\trftsWidthB3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid2981395\tbllkhdrrows\tbllklastrow\tbllkhdrcols\tbllklastcol ";
			string s3 = @"\pard \ql \li0\ri0\widctlpar\intbl\aspalpha\aspnum\adjustright\rin0\lin0 \lang1033\langfe1033\cgrid\langnp1033\langfenp1033 ";
			string s4 = @"{";
			string s5 = @"}";
			string s6 = @"\pard \ql \li0\ri0\widctlpar\intbl\aspalpha\aspnum\adjustright\rin0\lin0 {";
			string s7 = @"\insrsid2981395 \trowd \irow0\irowband0\lastrow \ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10 ";
			string s8 = @"\trftsWidth1\trftsWidthB3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid2981395\tbllkhdrrows\tbllklastrow\tbllkhdrcols\tbllklastcol ";
			string s9 = @"\row }";
			sb.Append(Environment.NewLine);
			sb.Append("		private string GetRtfGrid(DataView dv)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			StringBuilder sb = new StringBuilder(\"\");" + Environment.NewLine);
			sb.Append("			try" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				int iColCnt = 0;" + Environment.NewLine);
			sb.Append("				DataTable dtAu;" + Environment.NewLine);
            //sb.Append("				if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("				{" + Environment.NewLine);
            //sb.Append("					dtAu = XmlUtils.XmlToDataTable(AdminFacade().GetAuthExp(" + screenId.ToString() + ",base.LUser.CultureId,XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr),LcSysConnString,LcAppPw));" + Environment.NewLine);
            //sb.Append("				}" + Environment.NewLine);
            //sb.Append("				else" + Environment.NewLine);
            //sb.Append("				{" + Environment.NewLine);
            sb.Append("				dtAu = (new AdminSystem()).GetAuthExp(" + screenId.ToString() + ",base.LUser.CultureId,base.LImpr,base.LCurr,LcSysConnString,LcAppPw);" + Environment.NewLine);
            //sb.Append("				}" + Environment.NewLine);
			sb.Append("				if (dtAu != null)" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
			ii = 0;
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (",Password,Image,drilldown,popup,Button,ImageButton,PlaceHolder,Document,".IndexOf("," + drv["DisplayMode"].ToString() + ",") < 0 && drv["ColumnId"].ToString() != string.Empty)
				{
					sb.Append("					if (dtAu.Rows[" + ii.ToString() + "][\"ColExport\"].ToString() == \"Y\") {iColCnt = iColCnt + 1;}" + Environment.NewLine);
				}
				ii = ii + 1;
			}
			sb.Append("					//Create Header" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s1 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s2 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(GenCellx(iColCnt));" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s3 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + sBoldBeg + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s4 + "\");" + Environment.NewLine);
			ii = 0;
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (",Password,Image,drilldown,popup,Button,ImageButton,PlaceHolder,Document,".IndexOf("," + drv["DisplayMode"].ToString() + ",") < 0 && drv["ColumnId"].ToString() != string.Empty && drv["DataTypeSqlName"].ToString().IndexOf("Text") < 0)
				{
					sb.Append("					if (dtAu.Rows[" + ii.ToString() + "][\"ColExport\"].ToString() == \"Y\") {sb.Append(dtAu.Rows[" + ii.ToString() + "][\"ColumnHeader\"].ToString() + @\"\\cell \");}" + Environment.NewLine);
				}
				ii = ii + 1;
			}
			sb.Append("					sb.Append(@\"" + s5 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + sBoldEnd + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s6 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s7 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s8 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(GenCellx(iColCnt));" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s9 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
			sb.Append("				//Create Data Rows" + Environment.NewLine);
			sb.Append("				foreach (DataRowView drv in dv)" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s1 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s2 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(GenCellx(iColCnt));" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s3 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s4 + "\");" + Environment.NewLine);
			ii = 0;
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (",Password,Image,drilldown,popup,Button,ImageButton,PlaceHolder,Document,".IndexOf("," + drv["DisplayMode"].ToString() + ",") < 0 && drv["ColumnId"].ToString() != string.Empty && drv["DataTypeSqlName"].ToString().IndexOf("Text") < 0)
                {
                    sb.Append("					if (dtAu.Rows[" + ii.ToString() + "][\"ColExport\"].ToString() == \"Y\") {sb.Append(");
                    if (drv["DisplayMode"].ToString().ToLower() == "currency")
                    {
                        sb.Append("base.fxCurrency(drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()");
                        sb.Append(string.IsNullOrEmpty(drv["DdlKeyColumnName"].ToString()) ? ",base.LUser.Culture" : ",drv[\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "\"].ToString()");
                        sb.Append(string.IsNullOrEmpty(drv["DdlRefColumnName"].ToString()) ? ",base.LUser.Culture)" : ",drv[\"" + drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString() + "\"].ToString())");
                    }
                    else
                    {
                        sb.Append(Robot.DataTypeConvert("Zf", drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), true).Replace("LongDate", "ShortDate") + "drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
                        // Listbox and DataGrid are currently multiple selection and may return duplicate rows:
                        if (",ComboBox,DropDownList,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("Text"); } { sb.Append("\"].ToString()"); }
                        if (drv["DataTypeSysName"].ToString() == "String") { sb.Append(".Replace(\"\\r\\n\",@\"\\par \")"); }
                        sb.Append(Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), string.Empty, false));
                    }
                    sb.Append(" + @\"\\cell \");}" + Environment.NewLine);
                }
				ii = ii + 1;
			}
			sb.Append("					sb.Append(@\"" + s5 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s6 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s7 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s8 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(GenCellx(iColCnt));" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(@\"" + s9 + "\");" + Environment.NewLine);
			sb.Append("					sb.Append(\"" + sLine + "\");" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
			sb.Append("				sb.Append(@\"\\pard \\par }\");" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("			return sb.ToString();" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private StringBuilder GenCellx(int CellCnt)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			StringBuilder sb = new StringBuilder(\"\");" + Environment.NewLine);
			sb.Append("			string strRowPre = @\"\\clvertalt\\clbrdrt\\brdrs\\brdrw10 \\clbrdrl\\brdrs\\brdrw10 \\clbrdrb\\brdrs\\brdrw10 \\clbrdrr\\brdrs\\brdrw10 \\cltxlrtb\\clftsWidth3\\clwWidth4428\\clshdrawnil \";" + Environment.NewLine);
			sb.Append("			for (int cnt=0; cnt<CellCnt; cnt++) {sb.Append(strRowPre + @\"\\cellx\" + cnt.ToString() + \" \");}" + Environment.NewLine);
			sb.Append("			return sb;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
            string DocTs = string.Empty;
            string DocFi = string.Empty;
            string DocPn = string.Empty;
            string DocTx = string.Empty;
            string DocDv = string.Empty;
            string DocIm = string.Empty;
            dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
                if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y")
                {
                    DocTs = "!string.IsNullOrEmpty(c" + pMKeyColumn + ".Text)";
                    DocFi = "c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Fi";
                    DocPn = "c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pan";
                    DocTx = "c" + drv["ColumnName"].ToString() + drv["TableId"].ToString();
                    DocDv = "c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div";
                    DocIm = "c" + drv["ColumnName"].ToString() + drv["TableId"].ToString();
                }
                else
                {
                    DocTs = "c" + dw["ProgramName"].ToString() + "Grid.EditIndex > -1 && c" + dw["ProgramName"].ToString() + "Grid.Items.Count > c" + dw["ProgramName"].ToString() + "Grid.EditIndex";
                    DocFi = "((FileUpload)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Fi\"))";
                    DocPn = "((Panel)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pan\"))";
                    DocTx = "((TextBox)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"))";
                    DocDv = "((TextBox)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div\"))";
                    DocIm = "((ImageButton)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"))";
                }
                if (",document,upload,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0)
                {
                    sb.Append(Environment.NewLine);
                    sb.Append("		public void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Upl_Click(object sender, System.EventArgs e)" + Environment.NewLine);
                    sb.Append("		{" + Environment.NewLine);
                    if (drv["DisplayMode"].ToString().ToLower() == "document")  // Not ready for grid.
                    {
                        sb.Append("			if (" + DocTs + " && " + DocFi + ".HasFile && " + DocFi + ".PostedFile.FileName != string.Empty)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("				if (c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Fi.PostedFile.FileName.Length > 100)" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        sb.Append("					bErrNow.Value = \"Y\"; PreMsgPopup(\"Filename exceeds a total of 100 characters. Please shorten the filename and upload again.\");" + Environment.NewLine);
                        sb.Append("				}" + Environment.NewLine);
                        sb.Append("				else" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        sb.Append("					byte[] dc;" + Environment.NewLine);
                        sb.Append("					if (\"image/gif,image/jpeg,image/png,image/tiff,image/pjpeg,image/x-png\".IndexOf(" + DocFi + ".PostedFile.ContentType) >= 0 && " + DocFi + ".PostedFile.ContentLength > int.Parse(Config.ImgThreshold) * 1024)" + Environment.NewLine);
                        sb.Append("					{" + Environment.NewLine);
                        sb.Append("						System.Drawing.Image oBMP = System.Drawing.Image.FromStream(" + DocFi + ".PostedFile.InputStream);" + Environment.NewLine);
                        sb.Append("						int nHeight = int.Parse((Math.Round(decimal.Parse(oBMP.Height.ToString()) * (decimal.Parse(Config.ImgThreshold) / decimal.Parse(oBMP.Width.ToString())))).ToString());" + Environment.NewLine);
                        sb.Append("						Bitmap nBMP = new Bitmap(oBMP, int.Parse(Config.ImgThreshold), nHeight);" + Environment.NewLine);
                        sb.Append("						using (System.IO.MemoryStream sm = new System.IO.MemoryStream())" + Environment.NewLine);
                        sb.Append("				    	{" + Environment.NewLine);
                        sb.Append("						    nBMP.Save(sm, System.Drawing.Imaging.ImageFormat.Jpeg);" + Environment.NewLine);
                        sb.Append("						    sm.Position = 0;" + Environment.NewLine);
                        sb.Append("						    dc = new byte[sm.Length + 1];" + Environment.NewLine);
                        sb.Append("						    sm.Read(dc, 0, dc.Length); sm.Close();" + Environment.NewLine);
                        sb.Append("					    }" + Environment.NewLine);
                        sb.Append("						oBMP.Dispose(); nBMP.Dispose();" + Environment.NewLine);
                        sb.Append("					}" + Environment.NewLine);
                        sb.Append("					else" + Environment.NewLine);
                        sb.Append("					{" + Environment.NewLine);
                        sb.Append("						dc = new byte[" + DocFi + ".PostedFile.ContentLength];" + Environment.NewLine);
                        sb.Append("						" + DocFi + ".PostedFile.InputStream.Read(dc, 0, dc.Length);" + Environment.NewLine);
                        sb.Append("					}" + Environment.NewLine);
                        sb.Append("					// In case DocId has not been saved properly, always find the most recent to replace as long as it has the same file name:" + Environment.NewLine);
                        sb.Append("					string DocId = string.Empty;" + Environment.NewLine);
                        string sConn = drv["MultiDesignDb"].ToString() == "N" ? "LcAppConnString" : "(string)Session[KEY_sysConnectionString]";
                        string sPwd = drv["MultiDesignDb"].ToString() == "N" ? "LcAppPw" : "base.AppPwd(LCurr.DbId)";
                        string altUpdDocFunction = string.IsNullOrEmpty(drv["MaskValid"].ToString()) ? null : drv["MaskValid"].ToString();
                        sb.Append("					DocId = " + (altUpdDocFunction ?? "new AdminSystem().GetDocId") + "(c" + pMKeyColumn + ".Text, \"dbo." + drv["DdlKeyTableName"].ToString() + "\", Path.GetFileName(" + DocFi + ".PostedFile.FileName), base.LUser.UsrId.ToString(), " + sConn + ", " + sPwd + ");" + Environment.NewLine);
                        sb.Append("					if (DocId == string.Empty || !c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Ow.Checked)" + Environment.NewLine);
                        sb.Append("					{" + Environment.NewLine);
                        sb.Append("						DocId = " + (altUpdDocFunction ?? "new AdminSystem().AddDbDoc") + "(c" + pMKeyColumn + ".Text, \"dbo." + drv["DdlKeyTableName"].ToString() + "\", Path.GetFileName(" + DocFi + ".PostedFile.FileName), " + DocFi + ".PostedFile.ContentType, dc.Length, dc, " + sConn + ", " + sPwd + ", base.LUser);" + Environment.NewLine);
                        sb.Append("					}" + Environment.NewLine);
                        sb.Append("					else" + Environment.NewLine);
                        sb.Append("					{" + Environment.NewLine);
                        sb.Append("						" + (altUpdDocFunction ?? "new AdminSystem().UpdDbDoc") + "(DocId, \"dbo." + drv["DdlKeyTableName"].ToString() + "\", Path.GetFileName(" + DocFi + ".PostedFile.FileName), " + DocFi + ".PostedFile.ContentType, dc.Length, dc, " + sConn + ", " + sPwd + ", base.LUser, c" + pMKeyColumn + ".Text);" + Environment.NewLine);
                        sb.Append("					}" + Environment.NewLine);
                        sb.Append("					" + DocPn + ".Visible = false; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Visible = true;" + Environment.NewLine);
                        sb.Append("					Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "GV, string.Empty);" + Environment.NewLine);
                        sb.Append("				}" + Environment.NewLine);
                    }
                    else if (drv["DisplayMode"].ToString().ToLower() == "upload")
                    {
                        sb.Append("			if (" + (!string.IsNullOrEmpty(drv["ColumnId"].ToString()) ? DocTs + " && " : "") + DocFi + ".HasFile && " + DocFi + ".PostedFile.FileName != string.Empty)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        if (drv["ColumnLink"].ToString() != string.Empty)
                        {
                            sb.Append("				string pth = " + (drv["ColumnLink"].ToString() == "TMP" ? "Config.PathTmpImport + \"" : "\"" + drv["ColumnLink"].ToString() + "/"));
                        }
                        else // Default:
                        {
                            sb.Append("				string pth = \"~/data/docs/");
                        }
                        sb.Append(dw["ProgramName"].ToString() + "_\"" + " + LcSystemId.ToString() + \"/\";" + Environment.NewLine);
                        if (drv["ColumnLink"].ToString() == "TMP")
                            sb.Append("				if (!Directory.Exists(pth)) { Directory.CreateDirectory(pth); }" + Environment.NewLine);
                        else
                            sb.Append("				if (!Directory.Exists(Server.MapPath(pth))) { Directory.CreateDirectory(Server.MapPath(pth)); }" + Environment.NewLine);
                        sb.Append("				string fname = pth + Regex.Replace((new FileInfo(" + DocFi + ".PostedFile.FileName)).Name, \"[ #=+]\", string.Empty);" + Environment.NewLine);
                        if (drv["ColumnLink"].ToString() != "TMP") { sb.Append("				fname = fname.Replace(\":\",\"\").Replace(\"..\",\"\");" + Environment.NewLine); }
                        sb.Append("				if (fname != string.Empty)" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        if (drv["ColumnLink"].ToString() == "TMP")
                        {
                            sb.Append("					if (fname.LastIndexOf(\".\") >= 0)" + Environment.NewLine);
                            sb.Append("					{" + Environment.NewLine);
                            sb.Append("						fname = fname.Insert(fname.LastIndexOf(\".\"), \"_\" + DateTime.Now.Hour.ToString(\"D2\") + DateTime.Now.Minute.ToString(\"D2\") + DateTime.Now.Second.ToString(\"D2\"));" + Environment.NewLine);
                            sb.Append("					}" + Environment.NewLine);
                            sb.Append("					else" + Environment.NewLine);
                            sb.Append("					{" + Environment.NewLine);
                            sb.Append("						fname = fname + \"_\" + DateTime.Now.Hour.ToString(\"D2\") + DateTime.Now.Minute.ToString(\"D2\") + DateTime.Now.Second.ToString(\"D2\");" + Environment.NewLine);
                            sb.Append("					}" + Environment.NewLine);
                            sb.Append("					" + DocFi + ".PostedFile.SaveAs(fname);" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("					if (File.Exists(Server.MapPath(fname))) { (new FileInfo(Server.MapPath(fname))).Delete(); }" + Environment.NewLine);
                            sb.Append("					" + DocFi + ".PostedFile.SaveAs(Server.MapPath(fname));" + Environment.NewLine);
                        }
                        sb.Append("					" + DocPn + ".Visible = false; " + DocTx + ".Visible = true;" + Environment.NewLine);
                        sb.Append("					" + DocTx + ".Text = fname; ShowDirty(true); " + DocTx + ".Focus();" + Environment.NewLine);
                        if ((drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y") && drv["ColumnIdentity"].ToString() != "Y")
                        {
                            sb.Append("					c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged(" + DocTx + ", null);" + Environment.NewLine);
                        }
                        sb.Append("				}" + Environment.NewLine);
                    }
                    else  // imagebutton with varbinary column:
                    {
                        // NO LONGER IN USE, this block is within document or upload, no way imagebutton is going to happen here

                        sb.Append("			if (" + DocTs + " && " + DocFi + ".HasFile && " + DocFi + ".PostedFile.FileName != string.Empty && \"image/gif,image/jpeg,image/png,image/tiff,image/pjpeg,image/x-png\".IndexOf(" + DocFi + ".PostedFile.ContentType) >= 0)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("				byte[] dc;" + Environment.NewLine);
                        sb.Append("				System.Drawing.Image oBMP = System.Drawing.Image.FromStream(" + DocFi + ".PostedFile.InputStream);" + Environment.NewLine);
                        if (string.IsNullOrEmpty(drv["ColumnSize"].ToString()) && string.IsNullOrEmpty(drv["ColumnHeight"].ToString()))
                        {
                            sb.Append("				int nWidth = int.Parse(oBMP.Width.ToString());" + Environment.NewLine);
                            sb.Append("				int nHeight = int.Parse(oBMP.Height.ToString());" + Environment.NewLine);
                        }
                        else if (!string.IsNullOrEmpty(drv["ColumnSize"].ToString()) && string.IsNullOrEmpty(drv["ColumnHeight"].ToString()))
                        {
                            sb.Append("				int nWidth = " + drv["ColumnSize"].ToString() + ";" + Environment.NewLine);
                            sb.Append("				int nHeight = int.Parse((Math.Round(decimal.Parse(oBMP.Height.ToString()) * (" + drv["ColumnSize"].ToString() + " / decimal.Parse(oBMP.Width.ToString())))).ToString());" + Environment.NewLine);
                        }
                        else /* Use height regardless */
                        {
                            sb.Append("				int nHeight = " + drv["ColumnHeight"].ToString() + ";" + Environment.NewLine);
                            sb.Append("				int nWidth = int.Parse((Math.Round(decimal.Parse(oBMP.Width.ToString()) * (" + drv["ColumnHeight"].ToString() + " / decimal.Parse(oBMP.Height.ToString())))).ToString());" + Environment.NewLine);
                        }
                        sb.Append("				Bitmap nBMP = new Bitmap(oBMP, nWidth, nHeight);" + Environment.NewLine);
                        sb.Append("				using (System.IO.MemoryStream sm = new System.IO.MemoryStream())" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        sb.Append("				    nBMP.Save(sm, System.Drawing.Imaging.ImageFormat.Jpeg);" + Environment.NewLine);
                        sb.Append("				    sm.Position = 0;" + Environment.NewLine);
                        sb.Append("				    dc = new byte[sm.Length + 1];" + Environment.NewLine);
                        sb.Append("				    sm.Read(dc, 0, dc.Length); sm.Close();" + Environment.NewLine);
                        sb.Append("				}" + Environment.NewLine);
                        sb.Append("				oBMP.Dispose(); nBMP.Dispose();" + Environment.NewLine);
                        string sConn = drv["MultiDesignDb"].ToString() == "N" ? "LcAppConnString" : "(string)Session[KEY_sysConnectionString]";
                        string sPwd = drv["MultiDesignDb"].ToString() == "N" ? "LcAppPw" : "base.AppPwd(LCurr.DbId)";

                        if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y")
                        {
                            sb.Append("				new AdminSystem().UpdDbImg(c" + pMKeyColumn + ".Text, \"" + (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".") + "dbo." + drv["TableName"].ToString() + "\", \"" + pMKey + "\", \"" + drv["ColName"].ToString() + "\", dc, " + sConn + ", " + sPwd + ");" + Environment.NewLine);
                            sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = \"data:application/base64;base64,\" + Convert.ToBase64String(dc);");
                            sb.Append("				" + DocPn + ".Visible = false; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Visible = true;" + Environment.NewLine);
                        }
                        else if ("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                        {
                            sb.Append("				new AdminSystem().UpdDbImg(((TextBox)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + pMKeyColumn + "\")).Text, \"" + (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".") + "dbo." + drv["TableName"].ToString() + "\", \"" + pMKey + "\", \"" + drv["ColName"].ToString() + "\", dc, " + sConn + ", " + sPwd + ");" + Environment.NewLine);
                            sb.Append("				ListViewCommandEventArgs eu = new ListViewCommandEventArgs(c" + dw["ProgramName"].ToString() + "Grid.EditItem, sender, new CommandEventArgs(\"Save\", \"\"));" + Environment.NewLine);
                            sb.Append("				DataTable dt" + dw["ProgramName"].ToString() + "Grid = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                            sb.Append("				DataRow dr" + dw["ProgramName"].ToString() + "Grid = dt" + dw["ProgramName"].ToString() + "Grid.DefaultView[eu.Item.DataItemIndex].Row;" + Environment.NewLine);
                            sb.Append("				dr" + dw["ProgramName"].ToString() + "Grid[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = dc;  // Making it visible." + Environment.NewLine);
                            sb.Append("				UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"));" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("				new AdminSystem().UpdDbImg(((TextBox)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + pDKeyColumn + "\")).Text, \"" + (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".") + "dbo." + drv["TableName"].ToString() + "\", \"" + pDKey + "\", \"" + drv["ColName"].ToString() + "\", dc, " + sConn + ", " + sPwd + ");" + Environment.NewLine);
                            sb.Append("				ListViewCommandEventArgs eu = new ListViewCommandEventArgs(c" + dw["ProgramName"].ToString() + "Grid.EditItem, sender, new CommandEventArgs(\"Save\", \"\"));" + Environment.NewLine);
                            sb.Append("				DataTable dt" + dw["ProgramName"].ToString() + "Grid = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                            sb.Append("				DataRow dr" + dw["ProgramName"].ToString() + "Grid = dt" + dw["ProgramName"].ToString() + "Grid.DefaultView[eu.Item.DataItemIndex].Row;" + Environment.NewLine);
                            sb.Append("				dr" + dw["ProgramName"].ToString() + "Grid[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = dc;  // Making it visible." + Environment.NewLine);
                            sb.Append("				UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"));" + Environment.NewLine);
                        }
                        sb.Append("			}" + Environment.NewLine);
                        sb.Append("			else if (!(" + DocTs + ")) {PreMsgPopup(\"Please save the record first before upload\");}" + Environment.NewLine);
                        sb.Append("		}" + Environment.NewLine);
                        sb.Append(Environment.NewLine);
                        sb.Append("		public void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Del_Click(object sender, System.EventArgs e)" + Environment.NewLine);
                        sb.Append("		{" + Environment.NewLine);
                        sb.Append("			if (" + DocTs + ")" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y")
                        {
                            sb.Append("				new AdminSystem().UpdDbImg(c" + pMKeyColumn + ".Text, \"" + (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".") + "dbo." + drv["TableName"].ToString() + "\", \"" + pMKey + "\", \"" + drv["ColName"].ToString() + "\", null, " + sConn + ", " + sPwd + ");" + Environment.NewLine);
                            sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = GetUrlWithQSHash(\"~/DnLoad.aspx?key=\" + c" + pMKeyColumn + ".Text + \"&tbl=" + (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".") + "dbo." + drv["TableName"].ToString() + "&knm=" + drv["ColTblPK"].ToString() + "&col=" + drv["ColName"].ToString());
                            if (drv["DdlRefColumnId"].ToString() == string.Empty) { sb.Append("&sys=\" + base.LCurr.DbId.ToString());" + Environment.NewLine); }
                            else { sb.Append("&sys=" + drv["DdlKeySystemId"].ToString() + "\");" + Environment.NewLine); }
                            sb.Append("				" + DocPn + ".Visible = false; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Visible = true;" + Environment.NewLine);
                        }
                        else if ("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                        {
                            sb.Append("				new AdminSystem().UpdDbImg(((TextBox)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + pMKeyColumn + "\")).Text, \"" + (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".") + "dbo." + drv["TableName"].ToString() + "\", \"" + pMKey + "\", \"" + drv["ColName"].ToString() + "\", null, " + sConn + ", " + sPwd + ");" + Environment.NewLine);
                            sb.Append("				ListViewCommandEventArgs eu = new ListViewCommandEventArgs(c" + dw["ProgramName"].ToString() + "Grid.EditItem, sender, new CommandEventArgs(\"Save\", \"\"));" + Environment.NewLine);
                            sb.Append("				DataTable dt" + dw["ProgramName"].ToString() + "Grid = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                            sb.Append("				DataRow dr" + dw["ProgramName"].ToString() + "Grid = dt" + dw["ProgramName"].ToString() + "Grid.DefaultView[eu.Item.DataItemIndex].Row;" + Environment.NewLine);
                            sb.Append("				dr" + dw["ProgramName"].ToString() + "Grid[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = System.DBNull.Value;" + Environment.NewLine);
                            sb.Append("				UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"));" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("				new AdminSystem().UpdDbImg(((TextBox)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + pDKeyColumn + "\")).Text, \"" + (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".") + "dbo." + drv["TableName"].ToString() + "\", \"" + pDKey + "\", \"" + drv["ColName"].ToString() + "\", null, " + sConn + ", " + sPwd + ");" + Environment.NewLine);
                            sb.Append("				ListViewCommandEventArgs eu = new ListViewCommandEventArgs(c" + dw["ProgramName"].ToString() + "Grid.EditItem, sender, new CommandEventArgs(\"Save\", \"\"));" + Environment.NewLine);
                            sb.Append("				DataTable dt" + dw["ProgramName"].ToString() + "Grid = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                            sb.Append("				DataRow dr" + dw["ProgramName"].ToString() + "Grid = dt" + dw["ProgramName"].ToString() + "Grid.DefaultView[eu.Item.DataItemIndex].Row;" + Environment.NewLine);
                            sb.Append("				dr" + dw["ProgramName"].ToString() + "Grid[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = System.DBNull.Value;" + Environment.NewLine);
                            sb.Append("				UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"));" + Environment.NewLine);
                        }
                    }
                    sb.Append("			}" + Environment.NewLine);
                    sb.Append("		}" + Environment.NewLine);
                }
                if (",document,upload,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0 || (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton" && !string.IsNullOrEmpty(drv["ColumnId"].ToString()) && "I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y"))
                {
                    sb.Append(Environment.NewLine);
                    sb.Append("		public void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo_Click(object sender, System.Web.UI.ImageClickEventArgs e)" + Environment.NewLine);
                    sb.Append("		{" + Environment.NewLine);
                    if (drv["DisplayMode"].ToString().ToLower() == "document")
                    {
                        sb.Append("			if (c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Visible)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("				" + DocPn + ".Visible = true; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Visible = false;" + Environment.NewLine);
                        sb.Append("			}" + Environment.NewLine);
                        sb.Append("			else" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("				" + DocPn + ".Visible = false; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Visible = true;" + Environment.NewLine);
                        sb.Append("			}" + Environment.NewLine);
                    }
                    else if (drv["DisplayMode"].ToString().ToLower() == "upload")
                    {
                        sb.Append("			if (" + DocTx + ".Visible)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("				" + DocPn + ".Visible = true; " + DocTx + ".Visible = false;" + Environment.NewLine);
                        sb.Append("			}" + Environment.NewLine);
                        sb.Append("			else" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("				" + DocPn + ".Visible = false; " + DocTx + ".Visible = true;" + Environment.NewLine);
                        sb.Append("			}" + Environment.NewLine);
                    }
                    else // ImageButton:
                    {
                        sb.Append("			if (" + DocIm + ".Visible)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        if (drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                        {
                            sb.Append("				" + DocPn + ".Visible = true; " + DocIm + ".Visible = false;" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("				" + DocDv + ".Visible = true; " + DocIm + ".Visible = false;" + Environment.NewLine);
                        }
                        sb.Append("			}" + Environment.NewLine);
                        sb.Append("			else" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        if (drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                        {
                            sb.Append("				" + DocPn + ".Visible = false; " + DocIm + ".Visible = true;" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("				" + DocDv + ".Visible = false; " + DocIm + ".Visible = true;" + Environment.NewLine);
                        }
                        sb.Append("			}" + Environment.NewLine);
                    }
                    sb.Append("		}" + Environment.NewLine);
                }
                if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                {
                    CtrlToSet = "Ctrl" + drv["ColumnLink"].ToString().Substring(0, drv["ColumnLink"].ToString().IndexOf(".")).Replace("://", string.Empty);
                    sb.Append(Environment.NewLine);
                    sb.Append("		public void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Click(object sender, System.Web.UI.ImageClickEventArgs e)" + Environment.NewLine);
                    sb.Append("		{" + Environment.NewLine);
                    //if (clientFrwork == "1")
                    //{
                    //    sb.Append("			Session.Remove(\"CtrlToFocus\");" + Environment.NewLine);
                    //    if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")
                    //    {
                    //        if (",HyperLink,".IndexOf("," + pDKeyDisplay + ",") >= 0) { sb.Append("			TextBox pp = "); } else { sb.Append("			" + pDKeyDisplay + " pp = "); }
                    //    }
                    //    else
                    //    {
                    //        if (",HyperLink,".IndexOf("," + pMKeyDisplay + ",") >= 0) { sb.Append("			TextBox pp = "); } else { sb.Append("			" + pMKeyDisplay + " pp = "); }
                    //    }
                    //    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y")
                    //    {
                    //        sb.Append("c" + pMKeyColumn + ";" + Environment.NewLine);
                    //    }
                    //    else
                    //    {
                    //        sb.Append("((");
                    //        if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")
                    //        {
                    //            if (",HyperLink,".IndexOf("," + pDKeyDisplay + ",") >= 0) { sb.Append("TextBox"); }
                    //            else if (",ComboBox,".IndexOf("," + pDKeyDisplay + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
                    //            else { sb.Append(pDKeyDisplay); }
                    //            sb.Append(")c" + dw["ProgramName"].ToString() + "Grid.Items[c" + dw["ProgramName"].ToString() + "Grid.EditIndex].FindControl(\"c" + pDKeyColumn + "\"));" + Environment.NewLine);
                    //        }
                    //        else
                    //        {
                    //            if (",HyperLink,".IndexOf("," + pMKeyDisplay + ",") >= 0) { sb.Append("TextBox"); }
                    //            else if (",ComboBox,".IndexOf("," + pMKeyDisplay + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
                    //            else { sb.Append(pMKeyDisplay); }
                    //            sb.Append(")c" + dw["ProgramName"].ToString() + "Grid.Items[c" + dw["ProgramName"].ToString() + "Grid.EditIndex].FindControl(\"c" + pMKeyColumn + "\"));" + Environment.NewLine);
                    //        }
                    //    }
                    //}
                    if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("			TextBox cc = "); }
                    else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("			RoboCoder.WebControls.ComboBox cc = "); }
                    else { sb.Append("			" + drv["DisplayName"].ToString() + " cc = "); }
                    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y")
                    {
                        sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ";");
                    }
                    else
                    {
                        sb.Append("((");
                        if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("TextBox"); }
                        else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
                        else { sb.Append(drv["DisplayName"].ToString()); }
                        sb.Append(")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"));");
                    }
                    if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append(" cc.SetTbVisible();"); }
                    sb.Append(" Session[\"" + CtrlToSet + "\"] = ");
                    if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("cc.FocusID;" + Environment.NewLine); } else { sb.Append("cc.ClientID;" + Environment.NewLine); }
                    sb.Append("		}" + Environment.NewLine);
                    sb.Append(Environment.NewLine);
                    sb.Append("		public void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Script()" + Environment.NewLine);
                    sb.Append("		{" + Environment.NewLine);
                    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) < 0 || drv["MasterTable"].ToString() != "Y")
                    {
                        sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex > -1 && c" + dw["ProgramName"].ToString() + "Grid.Items.Count > c" + dw["ProgramName"].ToString() + "Grid.EditIndex)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                    }
                    sb.Append("				ImageButton ib = ");
                    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y")
                    {
                        sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + (drv["DisplayName"].ToString() == "ImageButton" ? "" : "Search") + ";" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append("(ImageButton)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + (drv["DisplayName"].ToString() == "ImageButton" ? "" : "Search") + "\");" + Environment.NewLine);
                    }
                    sb.Append("				if (ib != null)" + Environment.NewLine);
                    sb.Append("				{" + Environment.NewLine);
                    if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")
                    {
                        if (",HyperLink,".IndexOf("," + pDKeyDisplay + ",") >= 0) { sb.Append("				    TextBox pp = "); }
                        else if (",ComboBox,".IndexOf("," + pDKeyDisplay + ",") >= 0) { sb.Append("				    RoboCoder.WebControls.ComboBox pp = "); }
                        else { sb.Append("			    	" + pDKeyDisplay + " pp = "); }
                    }
                    else
                    {
                        if (",HyperLink,".IndexOf("," + pMKeyDisplay + ",") >= 0) { sb.Append("				    TextBox pp = "); }
                        else if (",ComboBox,".IndexOf("," + pMKeyDisplay + ",") >= 0) { sb.Append("				    RoboCoder.WebControls.ComboBox pp = "); }
                        else { sb.Append("			    	" + pMKeyDisplay + " pp = "); }
                    }
                    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y")
                    {
                        sb.Append("c" + pMKeyColumn + ";" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append("((");
                        if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")
                        {
                            if (",HyperLink,".IndexOf("," + pDKeyDisplay + ",") >= 0) { sb.Append("TextBox"); }
                            else if (",ComboBox,".IndexOf("," + pDKeyDisplay + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
                            else { sb.Append(pDKeyDisplay); }
                            sb.Append(")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + pDKeyColumn + "\"));" + Environment.NewLine);
                        }
                        else
                        {
                            if (",HyperLink,".IndexOf("," + pMKeyDisplay + ",") >= 0) { sb.Append("TextBox"); }
                            else if (",ComboBox,".IndexOf("," + pMKeyDisplay + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
                            else { sb.Append(pMKeyDisplay); }
                            sb.Append(")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + pMKeyColumn + "\"));" + Environment.NewLine);
                        }
                    }
                    if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("					TextBox cc = "); }
                    else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("					RoboCoder.WebControls.ComboBox cc = "); }
                    else { sb.Append("					" + drv["DisplayName"].ToString() + " cc = "); }
                    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y")
                    {
                        sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ";" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append("(");
                        if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("TextBox"); }
                        else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
                        else { sb.Append(drv["DisplayName"].ToString()); }
                        sb.Append(")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\");" + Environment.NewLine);
                    }
                    sb.Append("					string ss = \"");
                    if (drv["ColumnLink"].ToString().IndexOf("?") >= 0) { sb.Append("&"); } else { sb.Append("?"); }
                    sb.Append("dsp=");
                    if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("TextBox"); }
                    else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("ComboBox"); }	// No need for "RoboCoder.WebControls."
                    else { sb.Append(drv["DisplayName"].ToString()); }
                    sb.Append("\"; if (cSystem.Visible) {ss = ss + \"&sys=\" + cSystemId.SelectedValue;} else {ss = ss + \"&sys=" + CSrc.SrcSystemId.ToString() + "\";}" + Environment.NewLine);
                    string wostr = "'" + drv["ColumnLink"].ToString() + "\"";
                    if (drv["ColumnLink"].ToString().IndexOf("://") < 0)
                    {
                        //wostr = wostr + " + ss + \"&oid=" + drv["ScreenObjId"].ToString() + "\"";
                        wostr = wostr + " + ss";
                        if (drv["ColumnLink"].ToString().ToLower().IndexOf("?typ=") < 0 && drv["ColumnLink"].ToString().ToLower().IndexOf("&typ=") < 0)
                        {
                            wostr = wostr + " + \"&typ=N\"";
                        }
                        /* &frm and &pkey are used by UpLoadModule and is now obsolete:
                        wostr = wostr + "&frm=aspnetForm&pkey=\" + ";
                        if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")
                        {
                            if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + pDKeyDisplay + ",") >= 0) { wostr = wostr + "pp.SelectedValue"; } else { wostr = wostr + "pp.Text"; }
                        }
                        else
                        {
                            if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + pMKeyDisplay + ",") >= 0) { wostr = wostr + "pp.SelectedValue"; } else { wostr = wostr + "pp.Text"; }
                        }
                        */
                        if ((drv["ColumnLink"].ToString().ToLower().IndexOf("?col=") >= 0 || drv["ColumnLink"].ToString().ToLower().IndexOf("&col=") >= 0) && drv["ColumnLink"].ToString().ToLower().IndexOf("?key=") < 0 && drv["ColumnLink"].ToString().ToLower().IndexOf("&key=") < 0)
                        {
                            int ifr = drv["ColumnLink"].ToString().ToLower().IndexOf("col=") + 4;
                            int ito = drv["ColumnLink"].ToString().IndexOf("&", ifr);
                            string col = drv["ColumnLink"].ToString().Substring(ifr, ito >= 0 ? ito - ifr : drv["ColumnLink"].ToString().Length - ifr);
                            //wostr = wostr + " + \"&key=\" + ";
                            wostr = wostr + " + \"','\" + ";
                            if (col == pMKey)
                            {
                                if (",ComboBox,".IndexOf("," + pMKeyDisplay + ",") >= 0) { wostr = wostr + "pp.FocusID"; } else { wostr = wostr + "pp.ClientID"; }
                                //if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + pMKeyDisplay + ",") >= 0) { wostr = wostr + "pp.SelectedValue"; } else { wostr = wostr + "pp.Text"; }
                            }
                            else if (col == pDKey)
                            {
                                if (",ComboBox,".IndexOf("," + pDKeyDisplay + ",") >= 0) { wostr = wostr + "pp.FocusID"; } else { wostr = wostr + "pp.ClientID"; }
                                //if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + pDKeyDisplay + ",") >= 0) { wostr = wostr + "pp.SelectedValue"; } else { wostr = wostr + "pp.Text"; }
                            }
                            else
                            {
                                if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { wostr = wostr + "cc.FocusID"; } else { wostr = wostr + "cc.ClientID"; }
                                //if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { wostr = wostr + "cc.SelectedValue"; } else { wostr = wostr + "cc.Text"; }
                            }
                        }
                        else
                        {
                            wostr = wostr + " + \"','\"";       //Take care of no key situation.
                        }
                    }
                    else
                    {
                        wostr = wostr + " + \"','\"";       //Take care of no key situation.
                    }
                    wostr = wostr + " + \"','',''";
                    sb.Append("					ib.Attributes[\"onclick\"] = \"SearchLink(" + wostr + "); return false;\";" + Environment.NewLine);
                    sb.Append("				}" + Environment.NewLine);
                    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) < 0 || drv["MasterTable"].ToString() != "Y")
                    {
                        sb.Append("			}" + Environment.NewLine);
                    }
                    sb.Append("		}" + Environment.NewLine);
                }
			}
			sb.Append(Environment.NewLine);
			sb.Append("		public void cExpTxtButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			bWebRule = false;
			foreach (DataRowView drvr in dvWRule)
			{
				if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ExpTxt")
				{
					bWebRule = true;
					sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append(WrapConditionalWebRule("			", drvr));
				}
			}
			if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
			else
			{
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ExpTxt")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                        sb.Append(WrapConditionalWebRule("			", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
				sb.Append("			getReport(\"TXT\");" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ExpTxt")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
			}
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		public void cExpRtfButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			bWebRule = false;
			foreach (DataRowView drvr in dvWRule)
			{
				if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ExpRtf")
				{
					bWebRule = true;
					sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append(WrapConditionalWebRule("			", drvr));
				}
			}
			if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
			else
			{
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ExpRtf")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                        sb.Append(WrapConditionalWebRule("			", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
				sb.Append("			getReport(\"RTF\");" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ExpRtf")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                        sb.Append(WrapConditionalWebRule("			", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
			}
			sb.Append("		}" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append(Environment.NewLine);
				sb.Append("		private void GetPageInfo()" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			try" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				DataTable dt;" + Environment.NewLine);
                //sb.Append("				if (Config.Architect == \"W\")" + Environment.NewLine);
                //sb.Append("				{" + Environment.NewLine);
                //sb.Append("					dt = XmlUtils.XmlToDataTable((AdminFacade()).GetLastPageInfo(" + screenId.ToString() + ", base.LUser.UsrId, LcSysConnString, LcAppPw));" + Environment.NewLine);
                //sb.Append("				}" + Environment.NewLine);
                //sb.Append("				else" + Environment.NewLine);
                //sb.Append("				{" + Environment.NewLine);
                sb.Append("				dt = (new AdminSystem()).GetLastPageInfo(" + screenId.ToString() + ", base.LUser.UsrId, LcSysConnString, LcAppPw);" + Environment.NewLine);
                //sb.Append("				}" + Environment.NewLine);
				sb.Append("				cPgSize.Text = dt.Rows[0][\"LastPageInfo\"].ToString();" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
                sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
			}
			sb.Append(Environment.NewLine);
			sb.Append("		public void cClearCriButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			bWebRule = false;
			foreach (DataRowView drvr in dvWRule)
			{
				if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ClearCri")
				{
					bWebRule = true;
					sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append(WrapConditionalWebRule("			", drvr));
				}
			}
			if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
			else
			{
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ClearCri")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
                sb.Append("			System.Web.UI.WebControls.Calendar cCalendar;" + Environment.NewLine);
				sb.Append("			ListBox cListBox;" + Environment.NewLine);
				sb.Append("			RoboCoder.WebControls.ComboBox cComboBox;" + Environment.NewLine);
                sb.Append("			DropDownList cDropDownList;" + Environment.NewLine);
                sb.Append("			RadioButtonList cRadioButtonList;" + Environment.NewLine);
                sb.Append("			CheckBox cCheckBox;" + Environment.NewLine);
				sb.Append("			TextBox cTextBox;" + Environment.NewLine);
                sb.Append("			DataView dvCri = GetScrCriteria();" + Environment.NewLine);
                sb.Append("			foreach (DataRowView drv in dvCri)" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
                sb.Append("			    if (drv[\"DisplayName\"].ToString() == \"ComboBox\")	// Reset to page 1 by reassigning the datasource:" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
				sb.Append("					cComboBox = (RoboCoder.WebControls.ComboBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
                sb.Append("					if (cComboBox != null && cComboBox.Items.Count > 0) { cComboBox.DataSource = cComboBox.DataSource; cComboBox.SelectByValue(cComboBox.Items[0].Value, string.Empty, true); }" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
                sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"DropDownList\")" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
                sb.Append("					cDropDownList = (DropDownList)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
                sb.Append("					if (cDropDownList != null && cDropDownList.Items.Count > 0) { cDropDownList.SelectedIndex = 0; }" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
                sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"ListBox\")" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
                sb.Append("					cListBox = (ListBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
                sb.Append("					if (cListBox != null && cListBox.Items.Count > 0) { cListBox.SelectedIndex = 0; }" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
                sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"RadioButtonList\")" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
                sb.Append("					cRadioButtonList = (RadioButtonList)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
                sb.Append("					if (cRadioButtonList != null && cRadioButtonList.Items.Count > 0) { cRadioButtonList.SelectedIndex = 0; }" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
                sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"Calendar\")" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
                sb.Append("					cCalendar = (System.Web.UI.WebControls.Calendar)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
                sb.Append("					if (cCalendar != null)" + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
                sb.Append("					    if (drv[\"RequiredValid\"].ToString() == \"N\") { cCalendar.SelectedDates.Clear(); } else { cCalendar.SelectedDate = System.DateTime.Today; }" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
                sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"CheckBox\")" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
                sb.Append("					cCheckBox = (CheckBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
                sb.Append("					if (cCheckBox != null) { cCheckBox.Checked = false; }" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
				sb.Append("			    else" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
                sb.Append("					cTextBox = (TextBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
                sb.Append("					if (cTextBox != null)" + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
                sb.Append("					    if (drv[\"RequiredValid\"].ToString() == \"N\") { cTextBox.Text = string.Empty; } else if (drv[\"DisplayMode\"].ToString().IndexOf(\"Date\") >= 0) { cTextBox.Text = System.DateTime.Today.ToString(); } else { cTextBox.Text = \"0\"; }" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
                sb.Append("			cCriButton_Click(sender, e);" + Environment.NewLine);
                sb.Append("			if (cFilterId.Items.Count > 0) { cFilterId.SelectedIndex = 0; }" + Environment.NewLine);
                bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ClearCri")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
			}
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void GetCriteria(DataView dvCri)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			try" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				DataTable dt;" + Environment.NewLine);
            //sb.Append("				if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("				{" + Environment.NewLine);
            //sb.Append("					dt = XmlUtils.XmlToDataTable(AdminFacade().GetLastCriteria(int.Parse(dvCri.Count.ToString()) + 1, " + screenId.ToString() + ", 0, base.LUser.UsrId, LcSysConnString, LcAppPw));" + Environment.NewLine);
            //sb.Append("				}" + Environment.NewLine);
            //sb.Append("				else" + Environment.NewLine);
            //sb.Append("				{" + Environment.NewLine);
            sb.Append("				dt = (new AdminSystem()).GetLastCriteria(int.Parse(dvCri.Count.ToString()) + 1, " + screenId.ToString() + ", 0, base.LUser.UsrId, LcSysConnString, LcAppPw);" + Environment.NewLine);
            //sb.Append("				}" + Environment.NewLine);
            sb.Append("				cCriPanel.Visible = true;   // Enable cCriteria.Visible to be set:" + Environment.NewLine);
            sb.Append("				if (dt.Rows.Count <= 0) { cCriteria.Visible = false; }" + Environment.NewLine);
            //sb.Append("				else if ((bool)Session[KEY_bHiCriVisible] && (bool)Session[KEY_bShCriVisible])" + Environment.NewLine);
            //sb.Append("				{" + Environment.NewLine);
            //sb.Append("				    cCriteria.Visible = base.GetBool(dt.Rows[0][\"LastCriteria\"].ToString());" + Environment.NewLine);
            //sb.Append("				}" + Environment.NewLine);
            //sb.Append("				else {cCriteria.Visible = true;}" + Environment.NewLine);
            sb.Append("				if (!string.IsNullOrEmpty(Request.QueryString[\"key\"]) && bUseCri.Value == string.Empty)" + Environment.NewLine);
            sb.Append("				{" + Environment.NewLine);
            sb.Append("					cCriPanel.Visible = false; cClearCriButton.Visible = false;" + Environment.NewLine);
            sb.Append("				}" + Environment.NewLine);
            sb.Append("				else" + Environment.NewLine);
            sb.Append("				{" + Environment.NewLine);
            sb.Append("					cCriPanel.Visible = (cCriteria.Visible && cCriteria.Controls.Count > 2) || cFilter.Visible;" + Environment.NewLine);
            sb.Append("					if ((bool)Session[KEY_bClCriVisible]) {cClearCriButton.Visible = cCriteria.Visible && cCriteria.Controls.Count > 2;} else {cClearCriButton.Visible = false;}" + Environment.NewLine);
            //sb.Append("					if ((bool)Session[KEY_bHiCriVisible]) {cHideCriButton.Visible = cCriteria.Visible && cCriteria.Controls.Count > 2;} else {cHideCriButton.Visible = false;}" + Environment.NewLine);
            //sb.Append("					if ((bool)Session[KEY_bShCriVisible]) {cShowCriButton.Visible = !cCriteria.Visible && cCriteria.Controls.Count > 2;} else {cShowCriButton.Visible = false;}" + Environment.NewLine);
            sb.Append("				}" + Environment.NewLine);
            sb.Append("				if (!IsPostBack)" + Environment.NewLine);
            sb.Append("				{" + Environment.NewLine);
            sb.Append("					int jj = 0; // Zero-based to be consistent with SQL reporting." + Environment.NewLine);
            sb.Append("					foreach (DataRowView drv in dvCri)" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						if (Request.QueryString[\"Cri\" + jj.ToString()] != null)" + Environment.NewLine);
            sb.Append("						{" + Environment.NewLine);
            sb.Append("							dt.Rows[jj+1][\"LastCriteria\"] = Request.QueryString[\"Cri\" + jj.ToString()].ToString();" + Environment.NewLine);
            sb.Append("						}" + Environment.NewLine);
            sb.Append("						jj = jj + 1;" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("				}" + Environment.NewLine);
            sb.Append("			    SetCriteria(dt, dvCri);" + Environment.NewLine);
            sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void GetSelectedItems(ListBox cObj, string selectedItems)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			string selectedItem;" + Environment.NewLine);
			sb.Append("			bool finish;" + Environment.NewLine);
			sb.Append("			if (selectedItems == string.Empty)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				try {cObj.SelectedIndex = 0;} catch {}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			else" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				finish = false;" + Environment.NewLine);
			sb.Append("				while (!finish)" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
			sb.Append("					selectedItem = GetSelectedItem(ref selectedItems);" + Environment.NewLine);
			sb.Append("					if (selectedItem == string.Empty) { finish = true; }" + Environment.NewLine);
			sb.Append("					else" + Environment.NewLine);
			sb.Append("					{" + Environment.NewLine);
			sb.Append("						try { cObj.Items.FindByValue(selectedItem).Selected = true; }" + Environment.NewLine);
			sb.Append("						catch { finish = true; try {cObj.SelectedIndex = 0;} catch {} }" + Environment.NewLine);
			sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private string GetSelectedItem(ref string selectedItems)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			string selectedItem;" + Environment.NewLine);
			sb.Append("			int sIndex = selectedItems.IndexOf(\"'\");" + Environment.NewLine);
			sb.Append("			int eIndex = selectedItems.IndexOf(\"'\",sIndex + 1);" + Environment.NewLine);
			sb.Append("			if (sIndex >= 0 && eIndex >= 0)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				selectedItem = selectedItems.Substring(sIndex + 1, eIndex - sIndex - 1);" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			else" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				selectedItem = string.Empty;" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
			sb.Append("			selectedItems = selectedItems.Substring(eIndex + 1, selectedItems.Length - eIndex - 1);" + Environment.NewLine);
			sb.Append("			return selectedItem;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		protected void cCriButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            bWebRule = false;
            foreach (DataRowView drvr in dvWRule)
            {
                if (drvr["EventCode"].ToString() == "CRICHG")
                {
                    bWebRule = true;
                    sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append(WrapConditionalWebRule("   ", drvr));
                }
            }
            if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** Criteria Trigger (before) Web Rule starts here *** //" + Environment.NewLine); }
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || (dt != null && UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"))))" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
            }
            sb.Append("			if (IsPostBack && cCriteria.Visible) ReBindCriteria(GetScrCriteria());" + Environment.NewLine);
            sb.Append("			UpdCriteria(true);" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
				sb.Append("			c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.ClearSearch(); Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List);" + Environment.NewLine);
            }
            sb.Append("			Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, null);" + Environment.NewLine);
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("			}" + Environment.NewLine);
            }
            sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		private void SetCriteria(DataTable dt, DataView dvCri)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			Label cLabel;" + Environment.NewLine);
            sb.Append("			System.Web.UI.WebControls.Calendar cCalendar;" + Environment.NewLine);
            sb.Append("			ListBox cListBox;" + Environment.NewLine);
			sb.Append("			RoboCoder.WebControls.ComboBox cComboBox;" + Environment.NewLine);
            sb.Append("			DropDownList cDropDownList;" + Environment.NewLine);
            sb.Append("			RadioButtonList cRadioButtonList;" + Environment.NewLine);
            sb.Append("			CheckBox cCheckBox;" + Environment.NewLine);
			//sb.Append("			Rating cRating;" + Environment.NewLine);
			sb.Append("			TextBox cTextBox;" + Environment.NewLine);
            sb.Append("			DataTable dtCriHlp = GetScreenCriHlp();" + Environment.NewLine);
            sb.Append("			int ii = 1;" + Environment.NewLine);
			sb.Append("			try" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				foreach (DataRowView drv in dvCri)" + Environment.NewLine);
            sb.Append("				{" + Environment.NewLine);
            sb.Append("					cLabel = (Label)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString() + \"Label\");" + Environment.NewLine);
            sb.Append("					if (drv[\"DisplayName\"].ToString() == \"ComboBox\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
			sb.Append("						cComboBox = (RoboCoder.WebControls.ComboBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						string val = null; try {val=dt.Rows[ii][\"LastCriteria\"].ToString();} catch {};" + Environment.NewLine);
            sb.Append("						base.SetCriBehavior(cComboBox, null, cLabel, dtCriHlp.Rows[ii-1]);" + Environment.NewLine);
            //sb.Append("						if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            //sb.Append("							AdminFacade().MkGetScreenIn(\"" + screenId.ToString() + "\", drv[\"ScreenCriId\"].ToString(), \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), LcAppDb, LcDesDb, drv[\"MultiDesignDb\"].ToString(), LcSysConnString, LcAppPw);" + Environment.NewLine);
            //sb.Append("							cComboBox.DataSource = new DataView(XmlUtils.XmlToDataTable(AdminFacade().GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), drv[\"RequiredValid\"].ToString(), 0, string.Empty, XmlUtils.ObjectToXml(base.LImpr), XmlUtils.ObjectToXml(base.LCurr), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId))));" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
            //sb.Append("						else" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            sb.Append("						(new AdminSystem()).MkGetScreenIn(\"" + screenId.ToString() + "\", drv[\"ScreenCriId\"].ToString(), \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), LcAppDb, LcDesDb, drv[\"MultiDesignDb\"].ToString(), LcSysConnString, LcAppPw);" + Environment.NewLine);
            sb.Append("						DataView dv = new DataView((new AdminSystem()).GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), (new AdminSystem()).CountScrCri(drv[\"ScreenCriId\"].ToString(), drv[\"MultiDesignDb\"].ToString(), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv[\"RequiredValid\"].ToString(), 0, string.Empty, drv[\"DisplayMode\"].ToString() != \"AutoListBox\", val, base.LImpr, base.LCurr, drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));" + Environment.NewLine);
            sb.Append("						FilterCriteriaDdl(cCriteria, dv, drv);" + Environment.NewLine);
            sb.Append("						cComboBox.DataSource = dv;" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
			sb.Append("						try { cComboBox.SelectByValue(dt.Rows[ii][\"LastCriteria\"], string.Empty, false); } catch { try { cComboBox.SelectedIndex = 0; } catch { } }" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					else if (drv[\"DisplayName\"].ToString() == \"DropDownList\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cDropDownList = (DropDownList)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						base.SetCriBehavior(cDropDownList, null, cLabel, dtCriHlp.Rows[ii-1]);" + Environment.NewLine);
            //sb.Append("						if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            //sb.Append("							AdminFacade().MkGetScreenIn(\"" + screenId.ToString() + "\", drv[\"ScreenCriId\"].ToString(), \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), LcAppDb, LcDesDb, drv[\"MultiDesignDb\"].ToString(), LcSysConnString, LcAppPw);" + Environment.NewLine);
            //sb.Append("							cDropDownList.DataSource = new DataView(XmlUtils.XmlToDataTable(AdminFacade().GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), drv[\"RequiredValid\"].ToString(), 0, string.Empty, XmlUtils.ObjectToXml(base.LImpr), XmlUtils.ObjectToXml(base.LCurr), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId))));" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
            //sb.Append("						else" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            sb.Append("						(new AdminSystem()).MkGetScreenIn(\"" + screenId.ToString() + "\", drv[\"ScreenCriId\"].ToString(), \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), LcAppDb, LcDesDb, drv[\"MultiDesignDb\"].ToString(), LcSysConnString, LcAppPw);" + Environment.NewLine);
            sb.Append("						DataView dv = new DataView((new AdminSystem()).GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), (new AdminSystem()).CountScrCri(drv[\"ScreenCriId\"].ToString(), drv[\"MultiDesignDb\"].ToString(), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv[\"RequiredValid\"].ToString(), 0, string.Empty, base.LImpr, base.LCurr, drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));" + Environment.NewLine);
            sb.Append("						FilterCriteriaDdl(cCriteria, dv, drv);" + Environment.NewLine);
            sb.Append("						cDropDownList.DataSource = dv;" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
			sb.Append("						cDropDownList.DataBind();" + Environment.NewLine);
            sb.Append("						try { cDropDownList.Items.FindByValue(dt.Rows[ii][\"LastCriteria\"].ToString()).Selected = true; } catch { try { cDropDownList.SelectedIndex = 0; } catch { } }" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					else if (drv[\"DisplayName\"].ToString() == \"ListBox\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cListBox = (ListBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						string val = null; try {val=dt.Rows[ii][\"LastCriteria\"].ToString();} catch {};" + Environment.NewLine);
            sb.Append("						base.SetCriBehavior(cListBox, null, cLabel, dtCriHlp.Rows[ii-1]);" + Environment.NewLine);
            //sb.Append("						if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            //sb.Append("							AdminFacade().MkGetScreenIn(\"" + screenId.ToString() + "\", drv[\"ScreenCriId\"].ToString(), \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), LcAppDb, LcDesDb, drv[\"MultiDesignDb\"].ToString(), LcSysConnString, LcAppPw);" + Environment.NewLine);
            //sb.Append("							cListBox.DataSource = new DataView(XmlUtils.XmlToDataTable(AdminFacade().GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), drv[\"RequiredValid\"].ToString(), 0, string.Empty, XmlUtils.ObjectToXml(base.LImpr), XmlUtils.ObjectToXml(base.LCurr), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId))));" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
            //sb.Append("						else" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            sb.Append("						(new AdminSystem()).MkGetScreenIn(\"" + screenId.ToString() + "\", drv[\"ScreenCriId\"].ToString(), \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), LcAppDb, LcDesDb, drv[\"MultiDesignDb\"].ToString(), LcSysConnString, LcAppPw);" + Environment.NewLine);
            sb.Append("						DataView dv = new DataView((new AdminSystem()).GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), (new AdminSystem()).CountScrCri(drv[\"ScreenCriId\"].ToString(), drv[\"MultiDesignDb\"].ToString(), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv[\"RequiredValid\"].ToString(), 0, string.Empty, drv[\"DisplayMode\"].ToString() != \"AutoListBox\", val, base.LImpr, base.LCurr, drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));" + Environment.NewLine);
            sb.Append("						FilterCriteriaDdl(cCriteria, dv, drv);" + Environment.NewLine);
            sb.Append("						cListBox.DataSource = dv;" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
			sb.Append("						cListBox.DataBind();" + Environment.NewLine);
            sb.Append("						GetSelectedItems(cListBox, dt.Rows[ii][\"LastCriteria\"].ToString());" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					else if (drv[\"DisplayName\"].ToString() == \"RadioButtonList\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cRadioButtonList = (RadioButtonList)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						base.SetCriBehavior(cRadioButtonList, null, cLabel, dtCriHlp.Rows[ii-1]);" + Environment.NewLine);
            //sb.Append("						if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            //sb.Append("							AdminFacade().MkGetScreenIn(\"" + screenId.ToString() + "\", drv[\"ScreenCriId\"].ToString(), \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), LcAppDb, LcDesDb, drv[\"MultiDesignDb\"].ToString(), LcSysConnString, LcAppPw);" + Environment.NewLine);
            //sb.Append("							cRadioButtonList.DataSource = new DataView(XmlUtils.XmlToDataTable(AdminFacade().GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), drv[\"RequiredValid\"].ToString(), 0, string.Empty, XmlUtils.ObjectToXml(base.LImpr), XmlUtils.ObjectToXml(base.LCurr), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId))));" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
            //sb.Append("						else" + Environment.NewLine);
            //sb.Append("						{" + Environment.NewLine);
            sb.Append("						(new AdminSystem()).MkGetScreenIn(\"" + screenId.ToString() + "\", drv[\"ScreenCriId\"].ToString(), \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), LcAppDb, LcDesDb, drv[\"MultiDesignDb\"].ToString(), LcSysConnString, LcAppPw);" + Environment.NewLine);
            sb.Append("						DataView dv = new DataView((new AdminSystem()).GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), (new AdminSystem()).CountScrCri(drv[\"ScreenCriId\"].ToString(), drv[\"MultiDesignDb\"].ToString(), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv[\"RequiredValid\"].ToString(), 0, string.Empty, base.LImpr, base.LCurr, drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));" + Environment.NewLine);
            sb.Append("						FilterCriteriaDdl(cCriteria, dv, drv);" + Environment.NewLine);
            sb.Append("						cRadioButtonList.DataSource = dv;" + Environment.NewLine);
            //sb.Append("						}" + Environment.NewLine);
			sb.Append("						cRadioButtonList.DataBind();" + Environment.NewLine);
            sb.Append("						try { cRadioButtonList.Items.FindByValue(dt.Rows[ii][\"LastCriteria\"].ToString()).Selected = true; } catch { try { cRadioButtonList.SelectedIndex = 0; } catch { } }" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					else if (drv[\"DisplayName\"].ToString() == \"Calendar\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cCalendar = (System.Web.UI.WebControls.Calendar)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						base.SetCriBehavior(cCalendar, null, cLabel, dtCriHlp.Rows[ii-1]);" + Environment.NewLine);
            sb.Append("						if (dt.Rows[ii][\"LastCriteria\"].ToString() == string.Empty)" + Environment.NewLine);
            sb.Append("						{" + Environment.NewLine);
            sb.Append("							cCalendar.SelectedDates.Clear();" + Environment.NewLine);
            sb.Append("						}" + Environment.NewLine);
            sb.Append("						else" + Environment.NewLine);
            sb.Append("						{" + Environment.NewLine);
            sb.Append("							cCalendar.SelectedDate = DateTime.Parse(dt.Rows[ii][\"LastCriteria\"].ToString()); cCalendar.VisibleDate = cCalendar.SelectedDate;" + Environment.NewLine);
            sb.Append("						}" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					else if (drv[\"DisplayName\"].ToString() == \"CheckBox\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cCheckBox = (CheckBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						base.SetCriBehavior(cCheckBox, null, cLabel, dtCriHlp.Rows[ii-1]);" + Environment.NewLine);
            sb.Append("						if (dt.Rows[ii][\"LastCriteria\"].ToString() != string.Empty) { cCheckBox.Checked = base.GetBool(dt.Rows[ii][\"LastCriteria\"].ToString()); }" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else if (drv[\"DisplayName\"].ToString() == \"Rating\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						cRating = (Rating)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            //sb.Append("						base.SetCriBehavior(cRating, null, cLabel, dtCriHlp.Rows[ii-1]);" + Environment.NewLine);
            //sb.Append("						if (dt.Rows[ii][\"LastCriteria\"].ToString() != string.Empty) { cRating.CurrentRating = int.Parse(dt.Rows[ii][\"LastCriteria\"].ToString()); }" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("					else" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cTextBox = (TextBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						base.SetCriBehavior(cTextBox, null, cLabel, dtCriHlp.Rows[ii-1]);" + Environment.NewLine);
            sb.Append("						cTextBox.Text = dt.Rows[ii][\"LastCriteria\"].ToString();" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					ii = ii + 1;" + Environment.NewLine);
            sb.Append("				}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		private void ReBindCriteria(DataView dvCri)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			ListBox cListBox;" + Environment.NewLine);
            sb.Append("			RoboCoder.WebControls.ComboBox cComboBox;" + Environment.NewLine);
            sb.Append("			DropDownList cDropDownList;" + Environment.NewLine);
            sb.Append("			RadioButtonList cRadioButtonList;" + Environment.NewLine);
            sb.Append("			try" + Environment.NewLine);
            sb.Append("			{" + Environment.NewLine);
            sb.Append("				foreach (DataRowView drv in dvCri)" + Environment.NewLine);
            sb.Append("				{" + Environment.NewLine);
            sb.Append("					if (string.IsNullOrEmpty(drv[\"DdlFtrColumnId\"].ToString())  && drv[\"DisplayMode\"].ToString() != \"AutoListBox\" ) continue;" + Environment.NewLine);
            sb.Append("					if (drv[\"DisplayName\"].ToString() == \"ComboBox\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cComboBox = (RoboCoder.WebControls.ComboBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						string val = cComboBox.SelectedValue;" + Environment.NewLine);
            sb.Append("						DataView dv = new DataView((new AdminSystem()).GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), (new AdminSystem()).CountScrCri(drv[\"ScreenCriId\"].ToString(), drv[\"MultiDesignDb\"].ToString(), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv[\"RequiredValid\"].ToString(), 0, string.Empty, drv[\"DisplayMode\"].ToString() != \"AutoListBox\", val, base.LImpr, base.LCurr, drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));" + Environment.NewLine);
            sb.Append("						FilterCriteriaDdl(cCriteria, dv, drv);" + Environment.NewLine);
            sb.Append("						cComboBox.DataSource = dv;" + Environment.NewLine);
            sb.Append("						try { cComboBox.SelectByValue(val, string.Empty, false); } catch { try { cComboBox.SelectedIndex = 0; } catch { } }" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					else if (drv[\"DisplayName\"].ToString() == \"DropDownList\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cDropDownList = (DropDownList)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						string val = cDropDownList.SelectedValue;" + Environment.NewLine);
            sb.Append("						DataView dv = new DataView((new AdminSystem()).GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), (new AdminSystem()).CountScrCri(drv[\"ScreenCriId\"].ToString(), drv[\"MultiDesignDb\"].ToString(), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv[\"RequiredValid\"].ToString(), 0, string.Empty, base.LImpr, base.LCurr, drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));" + Environment.NewLine);
            sb.Append("						FilterCriteriaDdl(cCriteria, dv, drv);" + Environment.NewLine);
            sb.Append("						cDropDownList.DataSource = dv;" + Environment.NewLine);
            sb.Append("						cDropDownList.DataBind();" + Environment.NewLine);
            sb.Append("						try { cDropDownList.Items.FindByValue(val).Selected = true; } catch { try { cDropDownList.SelectedIndex = 0; } catch { } }" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					else if (drv[\"DisplayName\"].ToString() == \"ListBox\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cListBox = (ListBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						TextBox cTextBox = (TextBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString() + \"Hidden\");" + Environment.NewLine);
            sb.Append("						string selectedValues = string.Join(\",\", cListBox.Items.Cast<ListItem>().Where(x => x.Selected).Select(x => \"'\" + x.Value + \"'\").ToArray());" + Environment.NewLine);
            sb.Append("						if (drv[\"DisplayMode\"].ToString() == \"AutoListBox\" && cTextBox != null) selectedValues = cTextBox.Text ;" + Environment.NewLine);
            sb.Append("						DataView dv = new DataView((new AdminSystem()).GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), (new AdminSystem()).CountScrCri(drv[\"ScreenCriId\"].ToString(), drv[\"MultiDesignDb\"].ToString(), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv[\"RequiredValid\"].ToString(), 0, string.Empty, drv[\"DisplayMode\"].ToString() != \"AutoListBox\", selectedValues, base.LImpr, base.LCurr, drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));" + Environment.NewLine);
            sb.Append("						FilterCriteriaDdl(cCriteria, dv, drv);" + Environment.NewLine);
            sb.Append("						cListBox.DataSource = dv;" + Environment.NewLine);
            sb.Append("						cListBox.DataBind();" + Environment.NewLine);
            sb.Append("						GetSelectedItems(cListBox, selectedValues);" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					else if (drv[\"DisplayName\"].ToString() == \"RadioButtonList\")" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						cRadioButtonList = (RadioButtonList)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("						string val = cRadioButtonList.SelectedValue;" + Environment.NewLine);
            sb.Append("						DataView dv = new DataView((new AdminSystem()).GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), (new AdminSystem()).CountScrCri(drv[\"ScreenCriId\"].ToString(), drv[\"MultiDesignDb\"].ToString(), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)), drv[\"RequiredValid\"].ToString(), 0, string.Empty, base.LImpr, base.LCurr, drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId)));" + Environment.NewLine);
            sb.Append("						FilterCriteriaDdl(cCriteria, dv, drv);" + Environment.NewLine);
            sb.Append("						cRadioButtonList.DataSource = dv;" + Environment.NewLine);
            sb.Append("						cRadioButtonList.DataBind();" + Environment.NewLine);
            sb.Append("						try { cRadioButtonList.Items.FindByValue(val).Selected = true; } catch { try { cRadioButtonList.SelectedIndex = 0; } catch { } }" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("				}" + Environment.NewLine);
            sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch { }" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append("		private DataView GetScrCriteria()" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
			sb.Append("		    DataTable dtScrCri = (DataTable)Session[KEY_dtScrCri];" + Environment.NewLine);
            sb.Append("		    if (dtScrCri == null)" + Environment.NewLine);
            sb.Append("		    {" + Environment.NewLine);
			sb.Append("				try" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
            //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						dtScrCri = XmlUtils.XmlToDataTable(AdminFacade().GetScrCriteria(\"" + screenId.ToString() + "\", LcSysConnString, LcAppPw));" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            sb.Append("					dtScrCri = (new AdminSystem()).GetScrCriteria(\"" + screenId.ToString() + "\", LcSysConnString, LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
            sb.Append("				catch (Exception err) { ErrorTrace(err, \"critical\"); bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("		        Session[KEY_dtScrCri] = dtScrCri;" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
			sb.Append("		    return dtScrCri.DefaultView;" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		private void MakeScrGrpLab(DataRowView drv)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("		    Literal cLiteral = new Literal();" + Environment.NewLine);
			sb.Append("			string sLabelCss = drv[\"LabelCss\"].ToString();" + Environment.NewLine);
			sb.Append("			if (sLabelCss != string.Empty)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
            sb.Append("				if (sLabelCss.StartsWith(\".\")) {cLiteral.Text = \"<div class=\\\"\" + sLabelCss.Substring(1) + \"\\\">\";} else {cLiteral.Text = \"<div class=\\\"r-labelL\\\" style=\\\"\" + sLabelCss + \"\\\">\";}" + Environment.NewLine);
            sb.Append("			}" + Environment.NewLine);
            sb.Append("			else {cLiteral.Text = \"<div class=\\\"r-labelL\\\">\";}" + Environment.NewLine);
			sb.Append("		    cCriteria.Controls.Add(cLiteral);" + Environment.NewLine);
			sb.Append("		    Label cLabel = new Label(); cLabel.ID = \"x\" + drv[\"ColumnName\"].ToString() + \"Label\"; cLabel.CssClass = \"inp-lbl\"; cCriteria.Controls.Add(cLabel);" + Environment.NewLine);
            sb.Append("		    cLiteral = new Literal(); cLiteral.Text = \"</div>\"; cCriteria.Controls.Add(cLiteral);" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		private void MakeScrGrpInp(DataRowView drv)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
			sb.Append("			System.Web.UI.WebControls.Calendar cCalendar;" + Environment.NewLine);
			//sb.Append("			AjaxControlToolkit.CalendarExtender cCalendarExtender;" + Environment.NewLine);
			sb.Append("			ListBox cListBox;" + Environment.NewLine);
			sb.Append("			RoboCoder.WebControls.ComboBox cComboBox;" + Environment.NewLine);
			sb.Append("			DropDownList cDropDownList;" + Environment.NewLine);
			sb.Append("			RadioButtonList cRadioButtonList;" + Environment.NewLine);
			sb.Append("			CheckBox cCheckBox;" + Environment.NewLine);
			//sb.Append("			Rating cRating;" + Environment.NewLine);
			sb.Append("			TextBox cTextBox;" + Environment.NewLine);
			sb.Append("		    Literal cLiteral = new Literal();" + Environment.NewLine);
			sb.Append("			string sContentCss = drv[\"ContentCss\"].ToString();" + Environment.NewLine);
			sb.Append("			if (sContentCss != string.Empty)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
            sb.Append("				if (sContentCss.StartsWith(\".\")) {cLiteral.Text = \"<div class=\\\"\" + sContentCss.Substring(1) + \"\\\">\";} else {cLiteral.Text = \"<div class=\\\"r-content\\\" style=\\\"\" + sContentCss + \"\\\">\";}" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            sb.Append("			else {cLiteral.Text = \"<div class=\\\"r-content\\\">\";}" + Environment.NewLine);
			sb.Append("		    cCriteria.Controls.Add(cLiteral);" + Environment.NewLine);
			sb.Append("		    if (drv[\"DisplayName\"].ToString() == \"ComboBox\")" + Environment.NewLine);
            sb.Append("		    {" + Environment.NewLine);
			sb.Append("		        cComboBox = new RoboCoder.WebControls.ComboBox(); cComboBox.ID = \"x\" + drv[\"ColumnName\"].ToString(); cComboBox.CssClass = \"inp-ddl\"; cComboBox.SelectedIndexChanged += new EventHandler(cCriButton_Click);" + Environment.NewLine);
            sb.Append("		        cComboBox.DataValueField = drv[\"DdlKeyColumnName\"].ToString(); cComboBox.DataTextField = drv[\"DdlRefColumnName\"].ToString(); cComboBox.AutoPostBack = true;" + Environment.NewLine);
            sb.Append("		        if (drv[\"DisplayMode\"].ToString() == \"AutoComplete\")" + Environment.NewLine);
            sb.Append("		        {" + Environment.NewLine);
            sb.Append("			        WebControl wcFtr = (WebControl)cCriteria.FindControl(\"x\" + drv[\"DdlFtrColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("		            System.Collections.Generic.Dictionary<string, string> context = new System.Collections.Generic.Dictionary<string, string>();" + Environment.NewLine);
            //sb.Append("		            context[\"facade\"] = Config.Architect == \"W\" ? typeof(AdminWs).ToString() : typeof(AdminSystem).ToString();" + Environment.NewLine);
            sb.Append("		            context[\"method\"] = \"GetScreenIn\";" + Environment.NewLine);
            sb.Append("			        context[\"addnew\"] = \"Y\";" + Environment.NewLine);
            sb.Append("		            context[\"sp\"] = \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"requiredValid\"] = drv[\"RequiredValid\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"mKey\"] = drv[\"DdlKeyColumnName\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"mVal\"] = drv[\"DdlRefColumnName\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"mTip\"] = drv[\"DdlRefColumnName\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"mImg\"] = drv[\"DdlRefColumnName\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"ssd\"] = Request.QueryString[\"ssd\"];" + Environment.NewLine);
            sb.Append("		            context[\"scr\"] = \"" + screenId.ToString() + "\";" + Environment.NewLine);
            sb.Append("		            context[\"csy\"] = \"" + CSrc.SrcSystemId.ToString() + "\";" + Environment.NewLine);
            sb.Append("		            context[\"filter\"] = Utils.IsInt(cFilterId.SelectedValue)? cFilterId.SelectedValue : \"0\";" + Environment.NewLine);
            sb.Append("		            context[\"isSys\"] = \"N\";" + Environment.NewLine);
            sb.Append("		            context[\"conn\"] = drv[\"MultiDesignDb\"].ToString() == \"N\" ? string.Empty : KEY_sysConnectionString;" + Environment.NewLine);
            sb.Append("		            context[\"refColCID\"] = wcFtr != null ? wcFtr.ClientID : null;" + Environment.NewLine);
            sb.Append("		            context[\"refCol\"] = wcFtr != null ? drv[\"DdlFtrColumnName\"].ToString() : null;" + Environment.NewLine);
            sb.Append("		            context[\"refColDataType\"] = wcFtr != null ? drv[\"DdlFtrDataType\"].ToString() : null;" + Environment.NewLine);
            sb.Append("		            cComboBox.AutoCompleteUrl = \"AutoComplete.aspx/DdlSuggests\";" + Environment.NewLine);
            sb.Append("		            cComboBox.DataContext = context;" + Environment.NewLine);
            sb.Append("		            cComboBox.Mode = \"A\";" + Environment.NewLine);
            sb.Append("		        }" + Environment.NewLine);
            sb.Append("		        cCriteria.Controls.Add(cComboBox);" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
            sb.Append("		    else if (drv[\"DisplayName\"].ToString() == \"DropDownList\")" + Environment.NewLine);
            sb.Append("		    {" + Environment.NewLine);
            sb.Append("		        cDropDownList = new DropDownList(); cDropDownList.ID = \"x\" + drv[\"ColumnName\"].ToString(); cDropDownList.CssClass = \"inp-ddl\"; cDropDownList.SelectedIndexChanged += new EventHandler(cCriButton_Click);" + Environment.NewLine);
            sb.Append("		        cDropDownList.DataValueField = drv[\"DdlKeyColumnName\"].ToString(); cDropDownList.DataTextField = drv[\"DdlRefColumnName\"].ToString(); cDropDownList.AutoPostBack = true;" + Environment.NewLine);
            sb.Append("		        cCriteria.Controls.Add(cDropDownList);" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
            sb.Append("		    else if (drv[\"DisplayName\"].ToString() == \"ListBox\")" + Environment.NewLine);
            sb.Append("		    {" + Environment.NewLine);
            sb.Append("		        cListBox = new ListBox(); cListBox.ID = \"x\" + drv[\"ColumnName\"].ToString(); cListBox.SelectionMode = ListSelectionMode.Multiple; cListBox.CssClass = \"inp-pic\"; cListBox.SelectedIndexChanged += new EventHandler(cCriButton_Click);" + Environment.NewLine);
            sb.Append("		        cListBox.DataValueField = drv[\"DdlKeyColumnName\"].ToString(); cListBox.DataTextField = drv[\"DdlRefColumnName\"].ToString(); cListBox.AutoPostBack = true;" + Environment.NewLine);
            sb.Append("		        if (drv[\"RowSize\"].ToString() != string.Empty) {cListBox.Rows = int.Parse(drv[\"RowSize\"].ToString()); cListBox.Height = int.Parse(drv[\"RowSize\"].ToString()) * 16 + 7; }" + Environment.NewLine);
            sb.Append("		        cCriteria.Controls.Add(cListBox);" + Environment.NewLine);
            sb.Append("		        if (drv[\"DisplayMode\"].ToString() == \"AutoListBox\")" + Environment.NewLine);
            sb.Append("		        {" + Environment.NewLine);
            sb.Append("			        WebControl wcFtr = (WebControl)cCriteria.FindControl(\"x\" + drv[\"DdlFtrColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("		            System.Collections.Generic.Dictionary<string, string> context = new System.Collections.Generic.Dictionary<string, string>();" + Environment.NewLine);
            sb.Append("		            context[\"method\"] = \"GetScreenIn\";" + Environment.NewLine);
            sb.Append("			        context[\"addnew\"] = \"Y\";" + Environment.NewLine);
            sb.Append("		            context[\"sp\"] = \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"requiredValid\"] = drv[\"RequiredValid\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"mKey\"] = drv[\"DdlKeyColumnName\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"mVal\"] = drv[\"DdlRefColumnName\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"mTip\"] = drv[\"DdlRefColumnName\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"mImg\"] = drv[\"DdlRefColumnName\"].ToString();" + Environment.NewLine);
            sb.Append("		            context[\"ssd\"] = Request.QueryString[\"ssd\"];" + Environment.NewLine);
            sb.Append("		            context[\"scr\"] = \"" + screenId.ToString() + "\";" + Environment.NewLine);
            sb.Append("		            context[\"csy\"] = \"" + CSrc.SrcSystemId.ToString() + "\";" + Environment.NewLine);
            sb.Append("		            context[\"filter\"] = Utils.IsInt(cFilterId.SelectedValue)? cFilterId.SelectedValue : \"0\";" + Environment.NewLine);
            sb.Append("		            context[\"isSys\"] = \"N\";" + Environment.NewLine);
            sb.Append("		            context[\"conn\"] = drv[\"MultiDesignDb\"].ToString() == \"N\" ? string.Empty : KEY_sysConnectionString;" + Environment.NewLine);
            sb.Append("		            context[\"refColCID\"] = wcFtr != null ? wcFtr.ClientID : null;" + Environment.NewLine);
            sb.Append("		            context[\"refCol\"] = wcFtr != null ? drv[\"DdlFtrColumnName\"].ToString() : null;" + Environment.NewLine);
            sb.Append("		            context[\"refColDataType\"] = wcFtr != null ? drv[\"DdlFtrDataType\"].ToString() : null;" + Environment.NewLine);
            sb.Append("		            Session[\"" + dw["ProgramName"].ToString() + screenId.ToString() + "\" + cListBox.ID] = context;" + Environment.NewLine);
            sb.Append("		            cListBox.Attributes[\"ac_context\"] = \"" + dw["ProgramName"].ToString() + screenId.ToString() + "\" + cListBox.ID;" + Environment.NewLine);
            sb.Append("		            cListBox.Attributes[\"ac_url\"] = \"AutoComplete.aspx/DdlSuggestsEx\";" + Environment.NewLine);
            sb.Append("		            cListBox.Attributes[\"refColCID\"] = wcFtr != null ? wcFtr.ClientID : null;" + Environment.NewLine);
            sb.Append("		            cListBox.Attributes[\"searchable\"] = \"\";" + Environment.NewLine);
            sb.Append("		            TextBox tb = new TextBox(); tb.ID = \"x\" + drv[\"ColumnName\"].ToString() + \"Hidden\";tb.Attributes[\"style\"] = \"display:none;\";" + Environment.NewLine);
            sb.Append("		            cCriteria.Controls.Add(tb);" + Environment.NewLine);
            sb.Append("		        }" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
            sb.Append("		    else if (drv[\"DisplayName\"].ToString() == \"RadioButtonList\")" + Environment.NewLine);
            sb.Append("		    {" + Environment.NewLine);
            sb.Append("		        cRadioButtonList = new RadioButtonList(); cRadioButtonList.ID = \"x\" + drv[\"ColumnName\"].ToString(); cRadioButtonList.CssClass = \"inp-rad\"; cRadioButtonList.SelectedIndexChanged += new EventHandler(cCriButton_Click);" + Environment.NewLine);
            sb.Append("		        cRadioButtonList.DataValueField = drv[\"DdlKeyColumnName\"].ToString(); cRadioButtonList.DataTextField = drv[\"DdlRefColumnName\"].ToString(); cRadioButtonList.AutoPostBack = true; cRadioButtonList.RepeatDirection = System.Web.UI.WebControls.RepeatDirection.Horizontal;" + Environment.NewLine);
            sb.Append("		        cRadioButtonList.Attributes[\"OnClick\"] = \"this.focus();\";" + Environment.NewLine);
            sb.Append("		        cLiteral = new Literal(); cLiteral.Text = \"<div>\"; cCriteria.Controls.Add(cLiteral);" + Environment.NewLine);
            sb.Append("		        cCriteria.Controls.Add(cRadioButtonList);" + Environment.NewLine);
            sb.Append("		        cLiteral = new Literal(); cLiteral.Text = \"</div>\"; cCriteria.Controls.Add(cLiteral);" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
            sb.Append("		    else if (drv[\"DisplayName\"].ToString() == \"Calendar\")" + Environment.NewLine);
            sb.Append("		    {" + Environment.NewLine);
            sb.Append("		        cCalendar = new System.Web.UI.WebControls.Calendar(); cCalendar.ID = \"x\" + drv[\"ColumnName\"].ToString(); cCalendar.CssClass = \"inp-txt calendar\"; cCalendar.SelectionChanged += new EventHandler(cCriButton_Click); cCriteria.Controls.Add(cCalendar);" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
			sb.Append("		    else if (drv[\"DisplayName\"].ToString() == \"CheckBox\")" + Environment.NewLine);
			sb.Append("		    {" + Environment.NewLine);
			sb.Append("		        cCheckBox = new CheckBox(); cCheckBox.ID = \"x\" + drv[\"ColumnName\"].ToString(); cCheckBox.CssClass = \"inp-chk\"; cCheckBox.AutoPostBack = true; cCheckBox.CheckedChanged += new EventHandler(cCriButton_Click); cCriteria.Controls.Add(cCheckBox);" + Environment.NewLine);
            sb.Append("		        cCheckBox.Attributes[\"OnClick\"] = \"this.focus();\";" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
			sb.Append("		    else" + Environment.NewLine);
            sb.Append("		    {" + Environment.NewLine);
            sb.Append("		        cTextBox = new TextBox(); cTextBox.ID = \"x\" + drv[\"ColumnName\"].ToString(); cTextBox.CssClass = \"inp-txt\"; cTextBox.AutoPostBack = true; cTextBox.TextChanged += new EventHandler(cCriButton_Click);" + Environment.NewLine);
            sb.Append("		        if (drv[\"DisplayMode\"].ToString() == \"MultiLine\") { cTextBox.TextMode = TextBoxMode.MultiLine; }" + Environment.NewLine);
            sb.Append("		        else if (drv[\"DisplayMode\"].ToString() == \"Password\") { cTextBox.TextMode = TextBoxMode.Password; }" + Environment.NewLine);
			sb.Append("				if (drv[\"ColumnJustify\"].ToString() == \"L\") { cTextBox.Style.Value = \"text-align:left;\"; }" + Environment.NewLine);
			sb.Append("				else if (drv[\"ColumnJustify\"].ToString() == \"R\") { cTextBox.Style.Value = \"text-align:right;\"; }" + Environment.NewLine);
			sb.Append("				else { cTextBox.Style.Value = \"text-align:center;\"; }" + Environment.NewLine);
			sb.Append("		        cCriteria.Controls.Add(cTextBox);" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
			sb.Append("		    cLiteral = new Literal(); cLiteral.Text = \"</div>\"; cCriteria.Controls.Add(cLiteral);" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		private void SetCriHolder(int ii, DataView dvCri)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			Literal cLiteral;" + Environment.NewLine);
            sb.Append("			if (dvCri.Count > 0)" + Environment.NewLine);
            sb.Append("			{" + Environment.NewLine);
            sb.Append("			    foreach (DataRowView drv in dvCri)" + Environment.NewLine);
            sb.Append("			    {" + Environment.NewLine);
            sb.Append("			        cLiteral = new Literal(); cLiteral.Text = \"<div class=\\\"r-criteria\\\">\"; cCriteria.Controls.Add(cLiteral);" + Environment.NewLine);
            sb.Append("			        MakeScrGrpLab(drv);" + Environment.NewLine);
            sb.Append("			        MakeScrGrpInp(drv);" + Environment.NewLine);
            sb.Append("			        cLiteral = new Literal(); cLiteral.Text = \"</div>\"; cCriteria.Controls.Add(cLiteral);" + Environment.NewLine);
            sb.Append("			    }" + Environment.NewLine);
            sb.Append("			}" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            sb.Append("		private DataTable MakeColumns(DataTable dt)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("		    DataColumnCollection columns = dt.Columns;" + Environment.NewLine);
            sb.Append("		    DataView dvCri = GetScrCriteria();" + Environment.NewLine);
            sb.Append("		    foreach (DataRowView drv in dvCri)" + Environment.NewLine);
            sb.Append("		    {" + Environment.NewLine);
            sb.Append("		        if (drv[\"DataTypeSysName\"].ToString() == \"DateTime\") { columns.Add(drv[\"ColumnName\"].ToString(), typeof(DateTime)); }" + Environment.NewLine);
            sb.Append("		        else if (drv[\"DataTypeSysName\"].ToString() == \"Byte\") { columns.Add(drv[\"ColumnName\"].ToString(), typeof(Byte)); }" + Environment.NewLine);
            sb.Append("		        else if (drv[\"DataTypeSysName\"].ToString() == \"Int16\") { columns.Add(drv[\"ColumnName\"].ToString(), typeof(Int16)); }" + Environment.NewLine);
            sb.Append("		        else if (drv[\"DataTypeSysName\"].ToString() == \"Int32\") { columns.Add(drv[\"ColumnName\"].ToString(), typeof(Int32)); }" + Environment.NewLine);
            sb.Append("		        else if (drv[\"DataTypeSysName\"].ToString() == \"Int64\") { columns.Add(drv[\"ColumnName\"].ToString(), typeof(Int64)); }" + Environment.NewLine);
            sb.Append("		        else if (drv[\"DataTypeSysName\"].ToString() == \"Single\") { columns.Add(drv[\"ColumnName\"].ToString(), typeof(Single)); }" + Environment.NewLine);
            sb.Append("		        else if (drv[\"DataTypeSysName\"].ToString() == \"Double\") { columns.Add(drv[\"ColumnName\"].ToString(), typeof(Double)); }" + Environment.NewLine);
            sb.Append("		        else if (drv[\"DataTypeSysName\"].ToString() == \"Byte[]\") { columns.Add(drv[\"ColumnName\"].ToString(), typeof(Byte[])); }" + Environment.NewLine);
            sb.Append("		        else if (drv[\"DataTypeSysName\"].ToString() == \"Object\") { columns.Add(drv[\"ColumnName\"].ToString(), typeof(Object)); }" + Environment.NewLine);
            sb.Append("		        else { columns.Add(drv[\"ColumnName\"].ToString(), typeof(String)); }" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
            sb.Append("		    return dt;" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private DataSet UpdCriteria(bool bUpdate)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
            //sb.Append("			" + dw["ProgramName"].ToString() + screenId.ToString() + "In ds = new " + dw["ProgramName"].ToString() + screenId.ToString() + "In();" + Environment.NewLine);
            //sb.Append("			DataRow dr = ds.Tables[\"" + dw["ProgramName"].ToString() + screenId.ToString() + "In\"].NewRow();" + Environment.NewLine);
            //foreach (DataRowView drv in dvCri)
            //{
            //    if (",ListBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
            //    {
            //        sb.Append("			dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = \"(\";" + Environment.NewLine);
            //        sb.Append("			foreach (ListItem li in c" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "In.Items)" + Environment.NewLine);
            //        sb.Append("			{" + Environment.NewLine);
            //        sb.Append("				if (li.Selected)" + Environment.NewLine);
            //        sb.Append("				{" + Environment.NewLine);
            //        sb.Append("					if (dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"].ToString() != \"(\")" + Environment.NewLine);
            //        sb.Append("					{" + Environment.NewLine);
            //        sb.Append("						dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"].ToString() + \",\";" + Environment.NewLine);
            //        sb.Append("					}" + Environment.NewLine);
            //        sb.Append("					if (li.Value.ToString() != string.Empty) {dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"].ToString() + \"'\" + li.Value.ToString() + \"'\";}" + Environment.NewLine);
            //        sb.Append("				}" + Environment.NewLine);
            //        sb.Append("			}" + Environment.NewLine);
            //        if (drv["RequiredValid"].ToString() == "Y")
            //        {
            //            sb.Append("			dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"].ToString() + \")\";" + Environment.NewLine);
            //        }
            //        else
            //        {
            //            sb.Append("			if (dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"].ToString() == \"(\") {dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = string.Empty;} else {dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"].ToString() + \")\";}" + Environment.NewLine);
            //        }
            //    }
            //    else if (",Calendar,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
            //    {
            //        sb.Append("			if (c" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "In.SelectedDate > DateTime.Parse(\"0001-01-01\")) {dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = c" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "In.SelectedDate;}" + Environment.NewLine);
            //    }
            //    else if (",ComboBox,DropDownList,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
            //    {
            //        sb.Append("			if (c" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "In.SelectedIndex >= 0 && c" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "In.SelectedValue != string.Empty) {dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = c" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "In.SelectedValue;}" + Environment.NewLine);
            //    }
            //    else if (",CheckBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
            //    {
            //        sb.Append("			dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = base.SetBool(c" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "In.Checked);" + Environment.NewLine);
            //    }
            //    else if (",TextBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
            //    {
            //        sb.Append("			if (c" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "In.Text != string.Empty) {dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"] = c" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "In.Text;}" + Environment.NewLine);
            //    }
            //}
            //sb.Append("			ds.Tables[\"" + dw["ProgramName"].ToString() + screenId.ToString() + "In\"].Rows.Add(dr);" + Environment.NewLine);
            //sb.Append("			if (bUpdate && (Request.QueryString[\"typ\"] == null || Request.QueryString[\"typ\"] != \"N\")) {(new " + dw["ProgramName"].ToString() + "System()).Upd" + dw["ProgramName"].ToString() + "In(" + screenId.ToString() + ",base.LUser.UsrId,cCriteria.Visible,ds" + Robot.GetCnCall("N","N") + ");}" + Environment.NewLine);
            sb.Append("			System.Web.UI.WebControls.Calendar cCalendar;" + Environment.NewLine);
            sb.Append("			ListBox cListBox;" + Environment.NewLine);
			sb.Append("			RoboCoder.WebControls.ComboBox cComboBox;" + Environment.NewLine);
            sb.Append("			DropDownList cDropDownList;" + Environment.NewLine);
            sb.Append("			RadioButtonList cRadioButtonList;" + Environment.NewLine);
            sb.Append("			CheckBox cCheckBox;" + Environment.NewLine);
			//sb.Append("			Rating cRating;" + Environment.NewLine);
			sb.Append("			TextBox cTextBox;" + Environment.NewLine);
            sb.Append("			DataSet ds = new DataSet();" + Environment.NewLine);
            sb.Append("			ds.Tables.Add(MakeColumns(new DataTable(\"DtScreenIn\")));" + Environment.NewLine);
            sb.Append("			DataRow dr = ds.Tables[\"DtScreenIn\"].NewRow();" + Environment.NewLine);
            sb.Append("			DataView dvCri = GetScrCriteria();" + Environment.NewLine);
            sb.Append("			foreach (DataRowView drv in dvCri)" + Environment.NewLine);
            sb.Append("			{" + Environment.NewLine);
            sb.Append("			    if (drv[\"DisplayName\"].ToString() == \"ListBox\")" + Environment.NewLine);
            sb.Append("			    {" + Environment.NewLine);
            sb.Append("					cListBox = (ListBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("					bool isRequired = drv[\"RequiredValid\"].ToString() == \"Y\";" + Environment.NewLine);
            sb.Append("					if (cListBox != null)" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						int CriCnt = (new AdminSystem()).CountScrCri(drv[\"ScreenCriId\"].ToString(), drv[\"MultiDesignDb\"].ToString(), drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcSysConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId));" + Environment.NewLine);
            sb.Append("						int TotalChoiceCnt = new DataView((new AdminSystem()).GetScreenIn(\"" + screenId.ToString() + "\", \"GetDdl\" + drv[\"ColumnName\"].ToString() + LCurr.SystemId.ToString() + \"C\" + drv[\"ScreenCriId\"].ToString(), CriCnt, drv[\"RequiredValid\"].ToString(), 0, string.Empty, true, string.Empty, base.LImpr, base.LCurr, drv[\"MultiDesignDb\"].ToString() == \"N\" ? LcAppConnString : (string)Session[KEY_sysConnectionString], base.AppPwd(LCurr.DbId))).Count;" + Environment.NewLine);
            sb.Append("						string selectedValues = string.Join(\",\", cListBox.Items.Cast<ListItem>().Where(x => x.Selected).Select(x => \"'\" + x.Value + \"'\").ToArray());" + Environment.NewLine);
            sb.Append("						bool noneSelected = string.IsNullOrEmpty(selectedValues) || selectedValues == \"''\";" + Environment.NewLine);
            sb.Append("					    dr[drv[\"ColumnName\"].ToString()] = \"(\";" + Environment.NewLine);
            sb.Append("					    if (noneSelected && CriCnt+1 > TotalChoiceCnt) dr[drv[\"ColumnName\"].ToString()] = dr[drv[\"ColumnName\"].ToString()].ToString() + \"'-1'\";" + Environment.NewLine);
            sb.Append("					    foreach (ListItem li in cListBox.Items)" + Environment.NewLine);
            sb.Append("					    {" + Environment.NewLine);
            sb.Append("					        if (li.Selected || (noneSelected && !isRequired && !string.IsNullOrEmpty(li.Value)))" + Environment.NewLine);
            sb.Append("					        {" + Environment.NewLine);
            sb.Append("					            if (dr[drv[\"ColumnName\"].ToString()].ToString() != \"(\")" + Environment.NewLine);
            sb.Append("					            {" + Environment.NewLine);
            sb.Append("					                dr[drv[\"ColumnName\"].ToString()] = dr[drv[\"ColumnName\"].ToString()].ToString() + \",\";" + Environment.NewLine);
            sb.Append("					            }" + Environment.NewLine);
            sb.Append("					            dr[drv[\"ColumnName\"].ToString()] = dr[drv[\"ColumnName\"].ToString()].ToString() + \"'\" + li.Value + \"'\";" + Environment.NewLine);
            sb.Append("					        }" + Environment.NewLine);
            sb.Append("					    }" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					if (IsPostBack && drv[\"RequiredValid\"].ToString() == \"Y\" && string.IsNullOrEmpty(cListBox.SelectedValue))" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
			sb.Append("						bErrNow.Value = \"Y\"; PreMsgPopup(\"Criteria column: \" + drv[\"ColumnName\"].ToString() + \" cannot be empty. Please rectify and try again.\");" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
			sb.Append("					if (dr[drv[\"ColumnName\"].ToString()].ToString() == \"(''\" || dr[drv[\"ColumnName\"].ToString()].ToString() == \"(\") { dr[drv[\"ColumnName\"].ToString()] = string.Empty; } else { dr[drv[\"ColumnName\"].ToString()] = dr[drv[\"ColumnName\"].ToString()].ToString() + \")\"; }" + Environment.NewLine);
            sb.Append("			    }" + Environment.NewLine);
            sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"Calendar\")" + Environment.NewLine);
            sb.Append("			    {" + Environment.NewLine);
            sb.Append("					cCalendar = (System.Web.UI.WebControls.Calendar)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("					if (cCalendar != null && cCalendar.SelectedDate > DateTime.Parse(\"0001-01-01\")) { dr[drv[\"ColumnName\"].ToString()] = drv[\"DisplayMode\"].ToString() == \"CalendarUTC\" ? base.SetDateTimeUTC(cCalendar.SelectedDate.ToString(\"yyyy/MM/dd\"), !bUpdate) : cCalendar.SelectedDate.ToString(\"yyyy/MM/dd\"); }" + Environment.NewLine);
            sb.Append("			    }" + Environment.NewLine);
            sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"ComboBox\")" + Environment.NewLine);
            sb.Append("			    {" + Environment.NewLine);
			sb.Append("					cComboBox = (RoboCoder.WebControls.ComboBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("					if (IsPostBack && drv[\"RequiredValid\"].ToString() == \"Y\" && string.IsNullOrEmpty(cComboBox.SelectedValue))" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						bErrNow.Value = \"Y\"; PreMsgPopup(\"Criteria column: \" + drv[\"ColumnName\"].ToString() + \" cannot be empty. Please rectify and try again.\");" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					if (cComboBox != null && cComboBox.SelectedIndex >= 0 && cComboBox.SelectedValue != string.Empty) { dr[drv[\"ColumnName\"].ToString()] = cComboBox.SelectedValue; }" + Environment.NewLine);
            sb.Append("			    }" + Environment.NewLine);
            sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"DropDownList\")" + Environment.NewLine);
            sb.Append("			    {" + Environment.NewLine);
            sb.Append("					cDropDownList = (DropDownList)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("					if (IsPostBack && drv[\"RequiredValid\"].ToString() == \"Y\" && string.IsNullOrEmpty(cDropDownList.SelectedValue))" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						bErrNow.Value = \"Y\"; PreMsgPopup(\"Criteria column: \" + drv[\"ColumnName\"].ToString() + \" cannot be empty. Please rectify and try again.\");" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					if (cDropDownList != null && cDropDownList.SelectedIndex >= 0 && cDropDownList.SelectedValue != string.Empty) { dr[drv[\"ColumnName\"].ToString()] = cDropDownList.SelectedValue; }" + Environment.NewLine);
            sb.Append("			    }" + Environment.NewLine);
            sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"RadioButtonList\")" + Environment.NewLine);
            sb.Append("			    {" + Environment.NewLine);
            sb.Append("					cRadioButtonList = (RadioButtonList)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("					if (IsPostBack && drv[\"RequiredValid\"].ToString() == \"Y\" && string.IsNullOrEmpty(cRadioButtonList.SelectedValue))" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						bErrNow.Value = \"Y\"; PreMsgPopup(\"Criteria column: \" + drv[\"ColumnName\"].ToString() + \" cannot be empty. Please rectify and try again.\");" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					if (cRadioButtonList != null && cRadioButtonList.SelectedIndex >= 0 && cRadioButtonList.SelectedValue != string.Empty) { dr[drv[\"ColumnName\"].ToString()] = cRadioButtonList.SelectedValue; }" + Environment.NewLine);
            sb.Append("			    }" + Environment.NewLine);
            sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"CheckBox\")" + Environment.NewLine);
            sb.Append("			    {" + Environment.NewLine);
            sb.Append("					cCheckBox = (CheckBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("					if (cCheckBox != null) { dr[drv[\"ColumnName\"].ToString()] = base.SetBool(cCheckBox.Checked); }" + Environment.NewLine);
            sb.Append("			    }" + Environment.NewLine);
            //sb.Append("			    else if (drv[\"DisplayName\"].ToString() == \"Rating\")" + Environment.NewLine);
            //sb.Append("			    {" + Environment.NewLine);
            //sb.Append("					cRating = (Rating)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            //sb.Append("					if (cRating != null) { dr[drv[\"ColumnName\"].ToString()] = cRating.CurrentRating.ToString(); }" + Environment.NewLine);
            //sb.Append("			    }" + Environment.NewLine);
			sb.Append("			    else" + Environment.NewLine);
            sb.Append("			    {" + Environment.NewLine);
            sb.Append("					cTextBox = (TextBox)cCriteria.FindControl(\"x\" + drv[\"ColumnName\"].ToString());" + Environment.NewLine);
            sb.Append("					if (drv[\"RequiredValid\"].ToString() == \"Y\" && string.IsNullOrEmpty(cTextBox.Text))" + Environment.NewLine);
            sb.Append("					{" + Environment.NewLine);
            sb.Append("						if (IsPostBack) { bErrNow.Value = \"Y\"; PreMsgPopup(\"Criteria column: \" + drv[\"ColumnName\"].ToString() + \" cannot be empty. Please rectify and try again.\");}" + Environment.NewLine);
            sb.Append("						cTextBox.Text = drv[\"DisplayMode\"].ToString().Contains(\"Date\") ? DateTime.Today.Date.ToShortDateString() : \"?\";" + Environment.NewLine);
            sb.Append("					}" + Environment.NewLine);
            sb.Append("					if (cTextBox != null && cTextBox.Text != string.Empty) { dr[drv[\"ColumnName\"].ToString()] = (\",DateUTC,DateTimeUTC,ShortDateTimeUTC,LongDateTimeUTC,\".IndexOf(\",\" + drv[\"DisplayMode\"].ToString() + \",\") >= 0) ? SetDateTimeUTC(cTextBox.Text,!bUpdate) : (drv[\"DisplayName\"].ToString().Contains(\"Date\") ? (DateTime.Parse(cTextBox.Text,System.Threading.Thread.CurrentThread.CurrentCulture).ToString()): cTextBox.Text); }" + Environment.NewLine);
            sb.Append("			    }" + Environment.NewLine);
            sb.Append("			}" + Environment.NewLine);
            sb.Append("			ds.Tables[\"DtScreenIn\"].Rows.Add(dr);" + Environment.NewLine);
            //sb.Append("			if (bUpdate && (Request.QueryString[\"typ\"] == null || Request.QueryString[\"typ\"] != \"N\")) " + Environment.NewLine);
            sb.Append("			if (bUpdate) " + Environment.NewLine);
            sb.Append("			{" + Environment.NewLine);
			sb.Append("				try" + Environment.NewLine);
			sb.Append("				{" + Environment.NewLine);
            //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            //sb.Append("						AdminFacade().UpdScrCriteria(\"" + screenId.ToString() + "\", \"" + dw["ProgramName"].ToString() + screenId.ToString() + "\", XmlUtils.DataViewToXml(dvCri), base.LUser.UsrId, cCriteria.Visible, XmlUtils.DataSetToXml(ds), LcAppConnString, LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
            //sb.Append("					else" + Environment.NewLine);
            //sb.Append("					{" + Environment.NewLine);
            sb.Append("					(new AdminSystem()).UpdScrCriteria(\"" + screenId.ToString() + "\", \"" + dw["ProgramName"].ToString() + screenId.ToString() + "\", dvCri, base.LUser.UsrId, cCriteria.Visible, ds, LcAppConnString, LcAppPw);" + Environment.NewLine);
            //sb.Append("					}" + Environment.NewLine);
			sb.Append("				}" + Environment.NewLine);
            sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
			sb.Append("			}" + Environment.NewLine);
            sb.Append("			Session[KEY_dsScrCriVal] = ds;" + Environment.NewLine);
            sb.Append("			return ds;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && dvTab != null && dvTab.Count > 1)
			{
				sb.Append(Environment.NewLine);
				sb.Append("		private DataTable GetScreenTab()" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			CheckAuthentication(false);" + Environment.NewLine);
				sb.Append("			DataTable dtScreenTab = null;" + Environment.NewLine);
				sb.Append("			try" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
                sb.Append("				dtScreenTab = (new AdminSystem()).GetScreenTab(" + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw);" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
                sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
				sb.Append("			return dtScreenTab;" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
			}
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
				{
                    /* Need the following to create the appropriate s.proc. for master table */
                    using (GenScreensAccessBase dac = GetGenScreensAccess())
                    {
                        dac.GetScreenObjDdlById(screenId, Int32.Parse(drv["ScreenObjId"].ToString()), "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString(), drv["GenerateSp"].ToString(), appDatabase, sysDatabase, CPrj.SrcDesDatabase, pMKey, drv["MultiDesignDb"].ToString(), CSrc);
                    }
                    /* Need the following for _SelectedIndexChanged to work properly on refreshed data */
                    if (drv["DisplayName"].ToString() == "ComboBox")
                    {
                        sb.Append(Environment.NewLine);
                        sb.Append("		protected void cb" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(object sender, System.EventArgs e)" + Environment.NewLine);
                        sb.Append("		{" + Environment.NewLine);
                        sb.Append("			Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "((RoboCoder.WebControls.ComboBox)sender,string.Empty");
                        if (drv["DdlFtrColumnId"].ToString() != string.Empty)
                        {
                            dvs.RowFilter = string.Empty;
                            foreach (DataRowView drvs in dvs)
                            {
                                if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
                                {
                                    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drvs["MasterTable"].ToString() == "Y")
                                    {
                                        sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
                                    }
                                    else
                                    {
                                        sb.Append(",((" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\")).");
                                    }
                                    if (",ComboBox,DropDownList,RadioButtonList,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0) { sb.Append("SelectedValue"); } else { sb.Append("Text"); }
                                }
                            }
                        }
                        if (("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 || ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")) && drv["DisplayName"].ToString() == "ComboBox")
                        {
                            sb.Append(",c" + dw["ProgramName"].ToString() + "Grid.EditItem");
                        }
                        sb.Append(");" + Environment.NewLine);
                        sb.Append("		}" + Environment.NewLine);
                    }
					sb.Append(Environment.NewLine);
                    string sAddNew = ",false";
                    if (drv["DisplayName"].ToString() == "ComboBox" || drv["DisplayName"].ToString() == "DropDownList" || (drv["AllowNulls"].ToString() == "Y" && drv["RequiredValid"].ToString() == "N" && drv["DisplayMode"].ToString() != "Document")) { sAddNew = ",true"; }
                    sb.Append("		private void Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(");
					if (drv["DisplayMode"].ToString().ToLower() == "document") { sb.Append("GridView"); }
					else if (drv["DisplayName"].ToString() == "ComboBox") { sb.Append("RoboCoder.WebControls.ComboBox"); }
					else { sb.Append(drv["DisplayName"].ToString()); }
					sb.Append(" ddl, string keyId");
					if (drv["DdlFtrColumnId"].ToString() != string.Empty) {sb.Append(", string filtr");}
                    if (("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 || ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")) && drv["DisplayName"].ToString() == "ComboBox")
                    {
                        sb.Append(", ListViewItem li");
                    }
					sb.Append(")" + Environment.NewLine);
					sb.Append("		{" + Environment.NewLine);
                    if (drv["DisplayMode"].ToString() == "AutoComplete")
                    {
                        sb.Append("			System.Collections.Generic.Dictionary<string, string> context = new System.Collections.Generic.Dictionary<string, string>();" + Environment.NewLine);
                        sb.Append("			context[\"method\"] = \"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\";" + Environment.NewLine);
                        sb.Append("			context[\"addnew\"] = \"" + (sAddNew == ",false" ? "N" : "Y") + "\";" + Environment.NewLine);
                        sb.Append("			context[\"mKey\"] = \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\";" + Environment.NewLine);
                        sb.Append("			context[\"mVal\"] = \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\";" + Environment.NewLine);
                        sb.Append("			context[\"mTip\"] = \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\";" + Environment.NewLine);
                        sb.Append("			context[\"mImg\"] = \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\";" + Environment.NewLine);
                        sb.Append("			context[\"ssd\"] = Request.QueryString[\"ssd\"];" + Environment.NewLine);
                        sb.Append("			context[\"scr\"] = \"" + screenId.ToString() + "\";" + Environment.NewLine);
                        sb.Append("			context[\"csy\"] = \"" + CSrc.SrcSystemId.ToString() + "\";" + Environment.NewLine);
                        sb.Append("			context[\"filter\"] = Utils.IsInt(cFilterId.SelectedValue)? cFilterId.SelectedValue : \"0\";" + Environment.NewLine);
                        sb.Append("			context[\"isSys\"] = \"" + Robot.GetIsSys(dw["MultiDesignDb"].ToString(), "N") + "\";" + Environment.NewLine);
                        sb.Append("			context[\"conn\"] = " + (dw["MultiDesignDb"].ToString() == "N" ? "string.Empty;" : "KEY_sysConnectionString" + ";") + Environment.NewLine);
                        if (drv["DdlAdnColumnName"].ToString() != string.Empty && drv["DdlFtrColumnName"].ToString() != string.Empty)
                        {
                            if (dw["ScreenTypeName"].ToString() == "I3" || (dw["ScreenTypeName"].ToString() == "I2" && drv["MasterTable"].ToString() == "N" && drv["DdlFtrTableId"].ToString() == drv["TableId"].ToString()))   // drv["TableId"] is the detail table here.
                            {
                                sb.Append("			context[\"refColCID\"] = li != null ? li.FindControl(\"c" + drv["DdlFtrColumnName"].ToString() + drv["DdlFtrTableId"].ToString() + "\").ClientID : string.Empty;" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("			context[\"refColCID\"] = c" + drv["DdlFtrColumnName"].ToString() + drv["DdlFtrTableId"].ToString() + ".ClientID;" + Environment.NewLine);
                            }
                            sb.Append("			context[\"refCol\"] = \"" + drv["DdlAdnColumnName"].ToString() + "\";" + Environment.NewLine);
                            sb.Append("			context[\"refColDataType\"] = \"" + drv["DdlFtrDataType"].ToString() + "\";" + Environment.NewLine);
                        }
                        sb.Append("			ddl.AutoCompleteUrl = \"AutoComplete.aspx/DdlSuggests\";" + Environment.NewLine);
                        sb.Append("			ddl.DataContext = context;" + Environment.NewLine);
                        sb.Append("			if (ddl != null)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("			    DataView dv = null;" + Environment.NewLine);
                        sb.Append("				if (keyId == string.Empty && ddl.SearchText.StartsWith(\"**\")) {keyId = ddl.SearchText.Substring(2);}" + Environment.NewLine);
                        sb.Append("				try" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        sb.Append("					dv = new DataView((new AdminSystem()).GetDdl(" + screenId.ToString() + ",\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\"" + sAddNew + ",false,0,keyId" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr));" + Environment.NewLine);
                        sb.Append("				}" + Environment.NewLine);
                        sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                        sb.Append("				if (dv != null)" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                        {
                            //Filter on primary key of calling table:
                            sb.Append("					if (dv.Table.Columns.Contains(\"" + pMKey + "\"))" + Environment.NewLine);
                            sb.Append("					{" + Environment.NewLine);
                            sb.Append("						context[\"pMKeyColID\"] = c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.ClientID;" + Environment.NewLine);
                            sb.Append("						context[\"pMKeyCol\"] = \"" + pMKey + "\";" + Environment.NewLine);
                            sb.Append("						string ss = \"");
                            sb.Append("(" + pMKey + " is null\";" + Environment.NewLine);
                            sb.Append("						if (string.IsNullOrEmpty(c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue)) {ss = ss + \")\";} else {ss = ss + \" OR " + pMKey + " = ");
                            if (",Char,VarChar,NChar,NVarChar,SmallDateTime,DateTime,".IndexOf("," + pMKeySqlName + ",") >= 0) { sb.Append("'"); }
                            sb.Append("\" + c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue");
                            if (",Char,VarChar,NChar,NVarChar,SmallDateTime,DateTime,".IndexOf("," + pMKeySqlName + ",") >= 0) { sb.Append(" + \"'\""); }
                            sb.Append(" + \")\";}" + Environment.NewLine);
                            sb.Append("						dv.RowFilter = ss;" + Environment.NewLine);
                            sb.Append("					}" + Environment.NewLine);
                        }
                        sb.Append("					ddl.DataSource = dv; Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "] = dv.Table;" + Environment.NewLine);
                        sb.Append("				    try { ddl.SelectByValue(keyId,");
                        if (drv["DdlAdnColumnName"].ToString() != string.Empty && drv["DdlFtrColumnId"].ToString() != string.Empty)
                        {
                            bool filterColumnIsList = "TinyInt,SmallInt,Int,BigInt,Char,NChar".IndexOf(drv["DdlFtrDataType"].ToString()) >= 0 && drv["DdlAdnDataType"].ToString().Contains("VarChar");
                            sb.Append("filtr != string.Empty ? \"(" + drv["DdlAdnColumnName"].ToString() + " is null OR "
                                + (
                                filterColumnIsList ? " (',' + SUBSTRING(ISNULL(" + drv["DdlAdnColumnName"].ToString() + ",'()'),2,LEN(ISNULL(" + drv["DdlAdnColumnName"].ToString() + ",'()'))-2) + ',' LIKE '%," + Robot.QuoteRequired(true, drv["DdlFtrDataType"].ToString(), string.Empty).Replace("'", "''") + "\" + filtr + \"" + Robot.QuoteRequired(true, drv["DdlFtrDataType"].ToString(), string.Empty).Replace("'", "''") + ",%') "
                                                   : drv["DdlAdnColumnName"].ToString() + " = " + Robot.QuoteRequired(true, drv["DdlFtrDataType"].ToString(), string.Empty) + "\" + filtr + \"" + Robot.QuoteRequired(true, drv["DdlFtrDataType"].ToString(), string.Empty)
                                ) + ")\" : string.Empty");
                        }
                        else { sb.Append("string.Empty"); }
                        sb.Append(",true); } catch { try { ddl.SelectedIndex = 0; } catch { } }" + Environment.NewLine);
                        sb.Append("				}" + Environment.NewLine);
                        sb.Append("			}" + Environment.NewLine);
                    }
                    else
                    {
                        if (drv["DisplayMode"].ToString() == "AutoListBox")
                        {
                            sb.Append("			System.Collections.Generic.Dictionary<string, string> context = new System.Collections.Generic.Dictionary<string, string>();" + Environment.NewLine);
                            sb.Append("			context[\"method\"] = \"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\";" + Environment.NewLine);
                            sb.Append("			context[\"addnew\"] = \"" + (sAddNew == ",false" ? "N" : "Y") + "\";" + Environment.NewLine);
                            sb.Append("			context[\"mKey\"] = \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\";" + Environment.NewLine);
                            sb.Append("			context[\"mVal\"] = \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\";" + Environment.NewLine);
                            sb.Append("			context[\"mTip\"] = \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\";" + Environment.NewLine);
                            sb.Append("			context[\"mImg\"] = \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\";" + Environment.NewLine);
                            sb.Append("			context[\"ssd\"] = Request.QueryString[\"ssd\"];" + Environment.NewLine);
                            sb.Append("			context[\"scr\"] = \"" + screenId.ToString() + "\";" + Environment.NewLine);
                            sb.Append("			context[\"csy\"] = \"" + CSrc.SrcSystemId.ToString() + "\";" + Environment.NewLine);
                            sb.Append("			context[\"filter\"] = Utils.IsInt(cFilterId.SelectedValue)? cFilterId.SelectedValue : \"0\";" + Environment.NewLine);
                            sb.Append("			context[\"isSys\"] = \"" + Robot.GetIsSys(dw["MultiDesignDb"].ToString(), "N") + "\";" + Environment.NewLine);
                            sb.Append("			context[\"conn\"] = " + (dw["MultiDesignDb"].ToString() == "N" ? "string.Empty;" : "KEY_sysConnectionString" + ";") + Environment.NewLine);
                            if (drv["DdlAdnColumnName"].ToString() != string.Empty && drv["DdlFtrColumnName"].ToString() != string.Empty)
                            {
                                if (dw["ScreenTypeName"].ToString() == "I3" || (dw["ScreenTypeName"].ToString() == "I2" && drv["MasterTable"].ToString() == "N" && drv["DdlFtrTableId"].ToString() == drv["TableId"].ToString()))   // drv["TableId"] is the detail table here.
                                {
                                    sb.Append("			context[\"refColCID\"] = li != null ? li.FindControl(\"c" + drv["DdlFtrColumnName"].ToString() + drv["DdlFtrTableId"].ToString() + "\").ClientID : string.Empty;" + Environment.NewLine);
                                }
                                else
                                {
                                    sb.Append("			context[\"refColCID\"] = c" + drv["DdlFtrColumnName"].ToString() + drv["DdlFtrTableId"].ToString() + ".ClientID;" + Environment.NewLine);
                                }
                                sb.Append("			context[\"refCol\"] = \"" + drv["DdlAdnColumnName"].ToString() + "\";" + Environment.NewLine);
                                sb.Append("			context[\"refColDataType\"] = \"" + drv["DdlFtrDataType"].ToString() + "\";" + Environment.NewLine);
                            }
                            sb.Append("			Session[\"" + dw["ProgramName"].ToString() + screenId.ToString() + "\" + ddl.ID] = context;" + Environment.NewLine);
                            sb.Append("			ddl.Attributes[\"ac_context\"] = \"" + dw["ProgramName"].ToString() + screenId.ToString() + "\" + ddl.ID;" + Environment.NewLine);
                            sb.Append("			ddl.Attributes[\"ac_url\"] = \"AutoComplete.aspx/DdlSuggestsEx\";" + Environment.NewLine);
                            sb.Append("			c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Hidden.Text = keyId;" + Environment.NewLine);
                        }
                        if (drv["DisplayMode"].ToString().ToLower() == "document") { sb.Append("			DataView dv = null;" + Environment.NewLine); }
                        else
                        {
                            sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "];" + Environment.NewLine);
                            sb.Append("			DataView dv = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
                        }
                        sb.Append("			if (ddl != null)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("				string ss = string.Empty;" + Environment.NewLine);
                        if (drv["DdlAdnColumnName"].ToString() != string.Empty && drv["DdlFtrColumnId"].ToString() != string.Empty)
                        {
                            bool filterColumnIsList = "TinyInt,SmallInt,Int,BigInt,Char,NChar".IndexOf(drv["DdlFtrDataType"].ToString()) >= 0 && drv["DdlAdnDataType"].ToString().Contains("VarChar");
                            sb.Append("				if (filtr != string.Empty) {ss = \"(" + drv["DdlAdnColumnName"].ToString() + " is null OR "
                                + (filterColumnIsList
                                ? " (',' + SUBSTRING(ISNULL(" + drv["DdlAdnColumnName"].ToString() + ",'()'),2,LEN(ISNULL(" + drv["DdlAdnColumnName"].ToString() + ",'()'))-2) + ',' LIKE '%," + Robot.QuoteRequired(true, drv["DdlFtrDataType"].ToString(), string.Empty).Replace("'", "''") + "\" + filtr + \"" + Robot.QuoteRequired(true, drv["DdlFtrDataType"].ToString(), string.Empty).Replace("'", "''") + ",%') "
                                : drv["DdlAdnColumnName"].ToString() + " = " + Robot.QuoteRequired(true, drv["DdlFtrDataType"].ToString(), string.Empty) + "\" + filtr + \"" + Robot.QuoteRequired(true, drv["DdlFtrDataType"].ToString(), string.Empty)
                                ) + ")\";}" + Environment.NewLine);
                        }
                        if (",ComboBox,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 && drv["DisplayMode"].ToString() != "Document") { sb.Append("				ListItem li = null;" + Environment.NewLine); }
                        if (",DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 && drv["DisplayMode"].ToString() != "Document") { sb.Append("				bool bFirst = false" + (drv["DisplayMode"].ToString() == "AutoListBox" ? ",bMissing = false" : "") + ";" + Environment.NewLine); }
                        if (drv["DisplayMode"].ToString() != "Document") { sb.Append("				bool bAll = false;" + (drv["DisplayMode"].ToString() != "AutoListBox" ? " if (ddl.Enabled && ddl.Visible) {bAll = true;}" : "") + Environment.NewLine); }
                        sb.Append("				if (dv == null)" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        if (",DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 && drv["DisplayMode"].ToString() != "Document") { sb.Append("					bFirst = true;" + Environment.NewLine); }
                        sb.Append("					try" + Environment.NewLine);
                        sb.Append("					{" + Environment.NewLine);
                        if (drv["DisplayMode"].ToString().ToLower() == "document")
                        {
                            sb.Append("						dv = new DataView((new AdminSystem()).GetDdl(" + screenId.ToString() + ",\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\",false,false,0,c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr));" + Environment.NewLine);
                            sb.Append("						if (dv != null)" + Environment.NewLine);
                            sb.Append("						{" + Environment.NewLine);
                            sb.Append("							foreach (DataRowView drv in dv)" + Environment.NewLine);
                            sb.Append("							{" + Environment.NewLine);
                            sb.Append("								if (drv[\"DocLink\"].ToString().IndexOf(\"&sys=\") < 0)" + Environment.NewLine);
                            sb.Append("								{" + Environment.NewLine);
                            if (dw["SysProgram"].ToString() == "Y")
                            {
                                sb.Append("									drv[\"DocLink\"] = drv[\"DocLink\"] + \"&sys=\" + base.LCurr.DbId.ToString();" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("									drv[\"DocLink\"] = drv[\"DocLink\"] + \"&sys=" + CSrc.SrcSystemId.ToString() + "\";" + Environment.NewLine);
                            }
                            sb.Append("								}" + Environment.NewLine);
                            sb.Append("							}" + Environment.NewLine);
                            sb.Append("						}" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("						dv = new DataView((new AdminSystem()).GetDdl(" + screenId.ToString() + ",\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\"" + sAddNew + ",bAll,0,keyId" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr));" + Environment.NewLine);
                        }
                        sb.Append("					}" + Environment.NewLine);
                        sb.Append("					catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                        sb.Append("				}" + Environment.NewLine);
                        sb.Append("				if (dv != null)" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["DisplayMode"].ToString() != "Document")	// DataGridLink or DataGrid or GridView.
                        {
                            //Filter on primary key of calling table:
                            sb.Append("					if (dv.Table.Columns.Contains(\"" + pMKey + "\"))" + Environment.NewLine);
                            sb.Append("					{" + Environment.NewLine);
                            sb.Append("						ss = ");
                            if (drv["DdlAdnColumnName"].ToString() != string.Empty && drv["DdlFtrColumnName"].ToString() != string.Empty) { sb.Append("ss + \" AND "); } else { sb.Append("\""); }
                            sb.Append("(" + pMKey + " is null\";" + Environment.NewLine);
                            sb.Append("						if (string.IsNullOrEmpty(c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue)) {ss = ss + \")\";} else {ss = ss + \" OR " + pMKey + " = ");
                            if (",Char,VarChar,NChar,NVarChar,SmallDateTime,DateTime,".IndexOf("," + pMKeySqlName + ",") >= 0) { sb.Append("'"); }
                            sb.Append("\" + c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue");
                            if (",Char,VarChar,NChar,NVarChar,SmallDateTime,DateTime,".IndexOf("," + pMKeySqlName + ",") >= 0) { sb.Append(" + \"'\""); }
                            sb.Append(" + \")\";}" + Environment.NewLine);
                            if (drv["DisplayMode"].ToString() == "AutoListBox")
                            {
                                sb.Append("					context[\"pMKeyColID\"] = c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.ClientID;" + Environment.NewLine);
                                sb.Append("					context[\"pMKeyCol\"] = \"" + pMKey + "\";" + Environment.NewLine);
                                sb.Append("					ddl.Attributes[\"refColCID\"] = context.ContainsKey(\"refColCID\") ? context[\"refColCID\"] : null;" + Environment.NewLine);
                                sb.Append("					ddl.Attributes[\"pMKeyColID\"] = context.ContainsKey(\"pMKeyColID\") ? context[\"refColCID\"] : null;" + Environment.NewLine);
                            }
                            sb.Append("					}" + Environment.NewLine);
                        }
                        if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0)
                        {
                            if (drv["DisplayMode"].ToString() != "Document")
                            {
                                // To prevent the showing up of null radiobutton:
                                sb.Append("					if (!string.IsNullOrEmpty(keyId) && !ddl.Enabled) { ss = ss + (string.IsNullOrEmpty(ss) ? string.Empty : \" AND \") + \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + " is not NULL\"; }" + Environment.NewLine);
                                if (drv["DisplayName"].ToString() == "DataGrid")
                                {
                                    sb.Append("					ViewState[\"" + drv["ColumnName"].ToString() + "_RowFilter\"] = ss;" + Environment.NewLine);
                                }
                                sb.Append("					dv.RowFilter = ss;" + Environment.NewLine);
                            };
                            if (",DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("					ddl.CurrentPageIndex = 0;ddl.AllowPaging = dv.Count > ddl.PageSize;" + Environment.NewLine); }
                            else if (drv["DisplayMode"].ToString().ToLower() == "document") { sb.Append("					ddl.PageIndex = 0;" + Environment.NewLine); }
                            sb.Append("					ddl.DataSource = dv; ddl.DataBind();" + Environment.NewLine);
                        }
                        if (",ComboBox,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 && drv["DisplayMode"].ToString() != "Document")
                        {
                            if (drv["DisplayName"].ToString() == "ListBox")
                            {
                                sb.Append("					string key = keyId;" + Environment.NewLine);
                                sb.Append("					if (key.StartsWith(\"(\")) { key = key.Substring(1, key.Length - 2); }" + Environment.NewLine);
                                sb.Append("					if (key.IndexOf(\"'\") >= 0) { key = key.Replace(\"''\", char.ToString((char)191)).Replace(\"'\", string.Empty).Replace(char.ToString((char)191), \"''\"); }" + Environment.NewLine);
                                sb.Append("					string[] arr = key.Split(',');" + Environment.NewLine);
                                sb.Append("					foreach (string sel in arr)" + Environment.NewLine);
                                sb.Append("					{" + Environment.NewLine);
                                sb.Append("						li = ddl.Items.FindByValue(sel); if (li != null) {li.Selected = true; bFirst = true;}" + (drv["DisplayMode"].ToString() == "AutoListBox" ? " else {bMissing = true;}" : "") + Environment.NewLine);
                                sb.Append("					}" + Environment.NewLine);
                                sb.Append("					if (!bFirst" + (drv["DisplayMode"].ToString() == "AutoListBox" ? " || bMissing" : "") + ")" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("					li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}" + Environment.NewLine);
                                sb.Append("					else if (!bFirst)" + Environment.NewLine);
                            }
                            sb.Append("					{" + Environment.NewLine);
                            sb.Append("						try" + Environment.NewLine);
                            sb.Append("						{" + Environment.NewLine);
                            sb.Append("							dv = new DataView((new AdminSystem()).GetDdl(" + screenId.ToString() + ",\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\"" + sAddNew + ",bAll,0,keyId" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr));" + Environment.NewLine);
                            sb.Append("						}" + Environment.NewLine);
                            sb.Append("						catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                            sb.Append("						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();" + Environment.NewLine);
                            if (drv["DisplayName"].ToString() == "ListBox")
                            {
                                sb.Append("						foreach (string sel in arr)" + Environment.NewLine);
                                sb.Append("						{" + Environment.NewLine);
                                sb.Append("							li = ddl.Items.FindByValue(sel); if (li != null) {li.Selected = true;}" + Environment.NewLine);
                                sb.Append("						}" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}" + Environment.NewLine);
                            }
                            sb.Append("					}" + Environment.NewLine);
                            sb.Append("					if (dv.Count <= ");
                            if (drv["DisplayName"].ToString() == "DropDownList" || (drv["AllowNulls"].ToString() == "Y" && drv["RequiredValid"].ToString() == "N" && drv["DisplayMode"].ToString() != "Document")) { sb.Append("1"); } else { sb.Append("0"); }
                            sb.Append(" && keyId != string.Empty)	// In case invalid value casued by copy action." + Environment.NewLine);
                            sb.Append("					{" + Environment.NewLine);
                            sb.Append("						try" + Environment.NewLine);
                            sb.Append("						{" + Environment.NewLine);
                            sb.Append("							dv = new DataView((new AdminSystem()).GetDdl(" + screenId.ToString() + ",\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\"" + sAddNew + ",true,0,keyId" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr));" + Environment.NewLine);
                            sb.Append("						}" + Environment.NewLine);
                            sb.Append("						catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                            sb.Append("						dv.RowFilter = ss; ddl.DataSource = dv; ddl.DataBind();" + Environment.NewLine);
                            sb.Append("						li = ddl.Items.FindByValue(keyId); if (li != null) {li.Selected = true;}" + Environment.NewLine);
                            sb.Append("					}" + Environment.NewLine);
                        }
                        //if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        //{
                        //    sb.Append("					ddl.DataSource = dv;" + Environment.NewLine);
                        //    sb.Append("					if (keyId == string.Empty && ddl.SearchText.StartsWith(\"**\")) {keyId = ddl.SearchText.Substring(2);}" + Environment.NewLine);
                        //    sb.Append("					if (!ddl.SelectByValue(keyId,ss,true) && !bFirst)	//SelectByValue must be executed first" + Environment.NewLine);
                        //    sb.Append("					{" + Environment.NewLine);
                        //    sb.Append("						try" + Environment.NewLine);
                        //    sb.Append("						{" + Environment.NewLine);
                        //    sb.Append("							dv = new DataView((new AdminSystem()).GetDdl(" + screenId.ToString() + ",\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\"" + sAddNew + ",bAll,0,keyId" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr));" + Environment.NewLine);
                        //    sb.Append("						}" + Environment.NewLine);
                        //    sb.Append("						catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                        //    sb.Append("						ddl.DataSource = dv; ddl.SelectByValue(keyId,ss,true);" + Environment.NewLine);
                        //    sb.Append("					}" + Environment.NewLine);
                        //    sb.Append("					if (dv.Count <= 0 && keyId != string.Empty)	// In case invalid value casued by copy action." + Environment.NewLine);
                        //    sb.Append("					{" + Environment.NewLine);
                        //    sb.Append("						try" + Environment.NewLine);
                        //    sb.Append("						{" + Environment.NewLine);
                        //    sb.Append("						    dv = new DataView((new AdminSystem()).GetDdl(" + screenId.ToString() + ",\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\"" + sAddNew + ",true,0,keyId" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr));" + Environment.NewLine);
                        //    sb.Append("						}" + Environment.NewLine);
                        //    sb.Append("						catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                        //    sb.Append("						ddl.DataSource = dv; ddl.SelectByValue(keyId,ss,true);" + Environment.NewLine);
                        //    sb.Append("					}" + Environment.NewLine);
                        //}
                        if (drv["DisplayName"].ToString() == "ListBox")
                        {
                            sb.Append("					if (ddl.SelectedIndex < 0 && dv.Count > 0) { ddl.Items[0].Selected = true; }" + Environment.NewLine);
                        }
                        sb.Append("					");
                        //if (drv["DisplayName"].ToString() == "ComboBox") { sb.Append("if (bAll) "); }
                        sb.Append("Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "] = dv.Table;" + Environment.NewLine);
                        //if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        //{
                            //sb.Append("					if (keyId == string.Empty && bSearch) {ddl.ApplyFilter(ss);}" + Environment.NewLine);
                            //sb.Append("					if (keyId == string.Empty) {ddl.ApplyFilter(ss);}" + Environment.NewLine);
                        //}
                        sb.Append("				}" + Environment.NewLine);
                        sb.Append("			}" + Environment.NewLine);
                    }
					sb.Append("		}" + Environment.NewLine);
				}
			}
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append(Environment.NewLine);
				sb.Append("		private DataView Get" + dw["ProgramName"].ToString() + screenId.ToString() + "List()" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List];" + Environment.NewLine);
				sb.Append("			if (dt == null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				CheckAuthentication(false);" + Environment.NewLine);
                sb.Append("				int filterId = 0;" + Environment.NewLine);
                sb.Append("				string key = string.Empty;" + Environment.NewLine);
				sb.Append("				if (!string.IsNullOrEmpty(Request.QueryString[\"key\"]) && bUseCri.Value == string.Empty) { key = Request.QueryString[\"key\"].ToString(); }" + Environment.NewLine);
                sb.Append("				else if (Utils.IsInt(cFilterId.SelectedValue)) { filterId = int.Parse(cFilterId.SelectedValue); }" + Environment.NewLine);
				sb.Append("				try" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
                //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                //sb.Append("						try {dt = XmlUtils.XmlToDataTable(" + dw["ProgramName"].ToString() + "Facade().GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "(\"Y\"," + screenId.ToString() + ",0" + Robot.GetCnCall(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,key,string.Empty,XmlUtils.DataViewToXml(GetScrCriteria()),XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr),XmlUtils.DataSetToXml(UpdCriteria(false))));}" + Environment.NewLine);
                //sb.Append("						catch {dt = XmlUtils.XmlToDataTable(" + dw["ProgramName"].ToString() + "Facade().GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "(\"N\"," + screenId.ToString() + ",0" + Robot.GetCnCall(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,key,string.Empty,XmlUtils.DataViewToXml(GetScrCriteria()),XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr),XmlUtils.DataSetToXml(UpdCriteria(false))));}" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
                //sb.Append("					else" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                sb.Append("					try {dt = (new AdminSystem()).GetLis(" + screenId.ToString() + ",\"GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "\",true,\"Y\",0" + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,key,string.Empty,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false));}" + Environment.NewLine);
                sb.Append("					catch {dt = (new AdminSystem()).GetLis(" + screenId.ToString() + ",\"GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "\",true,\"N\",0" + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,key,string.Empty,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false));}" + Environment.NewLine);
                //sb.Append("						try {dt = (new " + dw["ProgramName"].ToString() + "System()).GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "(\"Y\"," + screenId.ToString() + ",0" + Robot.GetCnCall(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,key,string.Empty,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false));}" + Environment.NewLine);
                //sb.Append("						catch {dt = (new " + dw["ProgramName"].ToString() + "System()).GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "(\"N\"," + screenId.ToString() + ",0" + Robot.GetCnCall(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,key,string.Empty,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false));}" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
                sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return new DataView(); }" + Environment.NewLine);
				sb.Append("				dt = SetFunctionality(dt);" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
				sb.Append("			return (new DataView(dt,\"\",\"\",System.Data.DataViewRowState.CurrentRows));" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
			}
			sb.Append(Environment.NewLine);
			sb.Append("		private void Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(object sender, System.EventArgs e, bool bPageLoad, object ID)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				dv.RowFilter = "MasterTable = 'Y'";
                sb.Append("			DataView dv = Get" + dw["ProgramName"].ToString() + screenId.ToString() + "List();" + Environment.NewLine);
                sb.Append("			System.Collections.Generic.Dictionary<string, string> context = new System.Collections.Generic.Dictionary<string, string>();" + Environment.NewLine);
                sb.Append("			context[\"method\"] = \"GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "\";" + Environment.NewLine);
                // No need for sAddNew because it is always true for GetLis.
                sb.Append("			context[\"mKey\"] = \"" + pMKeyColumn + "\";" + Environment.NewLine);
                sb.Append("			context[\"mVal\"] = \"" + pMKeyColumn + "Text\";" + Environment.NewLine);
                sb.Append("			context[\"mTip\"] = \"" + pMKeyColumn + "Text\";" + Environment.NewLine);
                sb.Append("			context[\"mImg\"] = \"" + pMKeyColumn + "Text\";" + Environment.NewLine);
                sb.Append("			context[\"ssd\"] = Request.QueryString[\"ssd\"];" + Environment.NewLine);
                sb.Append("			context[\"scr\"] = \"" + screenId.ToString() + "\";" + Environment.NewLine);
                sb.Append("			context[\"csy\"] = \"" + CSrc.SrcSystemId.ToString() + "\";" + Environment.NewLine);
                sb.Append("			context[\"filter\"] = Utils.IsInt(cFilterId.SelectedValue) && cFilter.Visible ? cFilterId.SelectedValue : \"0\";" + Environment.NewLine);
                sb.Append("			context[\"isSys\"] = \"" + Robot.GetIsSys(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + "\";" + Environment.NewLine);
                sb.Append("			context[\"conn\"] = " + (dw["MultiDesignDb"].ToString() == "N" ? "string.Empty;" : "KEY_sysConnectionString" + ";") + Environment.NewLine);
                sb.Append("			c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.AutoCompleteUrl = \"AutoComplete.aspx/LisSuggests\";" + Environment.NewLine);
                sb.Append("			c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.DataContext = context;" + Environment.NewLine);
                sb.Append("			if (dv.Table == null) return;" + Environment.NewLine);
                sb.Append("			c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.DataSource = dv;" + Environment.NewLine);
				sb.Append("			c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.Visible = true;" + Environment.NewLine);
				sb.Append("			if (c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.Items.Count <= 0) {c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.Visible = false; c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_SelectedIndexChanged(sender,e);}" + Environment.NewLine);
				sb.Append("			else" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				if (bPageLoad && !string.IsNullOrEmpty(Request.QueryString[\"key\"]) && bUseCri.Value == string.Empty)" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					try {c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectByValue(Request.QueryString[\"key\"],string.Empty,true);} catch {c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.Items[0].Selected = true; c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_SelectedIndexChanged(sender, e);}" + Environment.NewLine);
                sb.Append("				    cScreenSearch.Visible = false; cSystem.Visible = false; cEditButton.Visible = true; cSaveCloseButton.Visible = cSaveButton.Visible;" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
				sb.Append("				else" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					if (ID != null) {if (!c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectByValue(ID,string.Empty,true)) {ID = null;}}" + Environment.NewLine);
				sb.Append("					if (ID == null)" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
                sb.Append("						c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_SelectedIndexChanged(sender, e);" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
			}
			else	// I3
			{
				sb.Append("			DataTable dt = null;" + Environment.NewLine);
				sb.Append("			CheckAuthentication(false);" + Environment.NewLine);
                sb.Append("			int filterId = 0; if (Utils.IsInt(cFilterId.SelectedValue)) { filterId = int.Parse(cFilterId.SelectedValue); }" + Environment.NewLine);
                sb.Append("			string key = string.Empty;" + Environment.NewLine);
				sb.Append("			if (!string.IsNullOrEmpty(Request.QueryString[\"key\"]) && bUseCri.Value == string.Empty)" + Environment.NewLine);
                sb.Append("		    {" + Environment.NewLine);
                sb.Append("		        key = Request.QueryString[\"key\"].ToString();" + Environment.NewLine);
                sb.Append("				cScreenSearch.Visible = false; cSystem.Visible = false; cEditButton.Visible = true; cSaveCloseButton.Visible = cSaveButton.Visible;" + Environment.NewLine);
                sb.Append("		    }" + Environment.NewLine);
				sb.Append("			try" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
                sb.Append("				try {dt = (new AdminSystem()).GetLis(" + screenId.ToString() + ",\"GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "\",false,\"Y\",0" + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,key,string.Empty,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false));}" + Environment.NewLine);
                sb.Append("				catch {dt = (new AdminSystem()).GetLis(" + screenId.ToString() + ",\"GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "\",false,\"N\",0" + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,key,string.Empty,GetScrCriteria(),base.LImpr,base.LCurr,UpdCriteria(false));}" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
                sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
				sb.Append("			if (dt != null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				CheckAuthentication(false);" + Environment.NewLine);
				sb.Append("				SetFunctionality();" + Environment.NewLine);
                //sb.Append("			    if (!dt.Columns.Contains(\"_CurRow\")) { dt.Columns.Add(\"_CurRow\"); }" + Environment.NewLine);
                sb.Append("			    if (!dt.Columns.Contains(\"_NewRow\")) { dt.Columns.Add(\"_NewRow\"); }" + Environment.NewLine);
                sb.Append("				Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dt;" + Environment.NewLine);
                sb.Append("				c" + dw["ProgramName"].ToString() + "GridDataPager.PageSize = Int16.Parse(cPgSize.Text); GotoPage(0);" + Environment.NewLine);
                sb.Append("			    if (Session[KEY_lastSortCol] != null)" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
                sb.Append("					c" + dw["ProgramName"].ToString() + "Grid_OnSorting(sender, new ListViewSortEventArgs((string)Session[KEY_lastSortExp], SortDirection.Ascending));" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
                sb.Append("				else" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
				sb.Append("					c" + dw["ProgramName"].ToString() + "Grid_DataBind(dt.DefaultView);" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
                sb.Append("				cFindButton_Click(sender, e);" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
				sb.Append("			ShowDirty(false); PanelTop.Update();" + Environment.NewLine);
				sb.Append("			cNaviPanel.Visible = true; cImportPwdPanel.Visible = false; Session.Remove(KEY_scrImport);" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "ENLSSE")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** List Selection (End of) Web Rule starts here *** //" + Environment.NewLine); }
			}
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		private void SetColumnAuthority()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			DataTable dtAuth = GetAuthCol();" + Environment.NewLine);
			sb.Append("			DataTable dtLabel = GetLabel();" + Environment.NewLine);
			dv.RowFilter = string.Empty;
			ii = 0;
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("			cTabFolder.CssClass = \"TabFolder rmvSpace\";" + Environment.NewLine);
				sb.Append("			foreach (DataRow dr in dtAuth.Rows) {if (dr[\"MasterTable\"].ToString() == \"Y\" && dr[\"ColVisible\"].ToString() == \"Y\") {cTabFolder.CssClass = \"TabFolder\"; break;}}" + Environment.NewLine);
				sb.Append("			if (dtAuth != null && dtLabel != null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				dv.RowFilter = "MasterTable = 'Y'";
				foreach (DataRowView drv in dv)
				{
					if (drv["DisplayMode"].ToString() != "PlaceHolder")
					{
						sb.Append("				base.SetFoldBehavior(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
						if (drv["DisplayMode"].ToString().ToLower() == "document") { sb.Append("GV"); }
						sb.Append(", dtAuth.Rows[" + ii.ToString() + "], ");
                        if (",Button,Label,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("null, null"); }
                        else { sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "P1, c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Label, c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "P2"); }
                        if (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton" && !string.IsNullOrEmpty(drv["ColumnId"].ToString()) && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary") { sb.Append(", c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo, c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pan"); }
                        else if (drv["DisplayMode"].ToString().ToLower() == "document" || (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton" && !string.IsNullOrEmpty(drv["ColumnId"].ToString()))) { sb.Append(", c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo, c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div"); }
                        else if (drv["DisplayMode"].ToString().ToLower() == "document" || (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton" && !string.IsNullOrEmpty(drv["ColumnId"].ToString()))) { sb.Append(", c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo, c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div"); }
                        else if (PopTextBox(drv)) { sb.Append(", c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "E, null"); }
                        else { sb.Append(", null"); }
						sb.Append(", dtLabel.Rows[" + ii.ToString() + "]");
						if (drv["ColumnIdentity"].ToString() != "Y")
						{
							if (drv["RequiredValid"].ToString() == "Y" && ",DropDownList,ComboBox,TextBox,ListBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append(", cRFV" + drv["ColumnName"].ToString() + drv["TableId"].ToString()); }
							else { sb.Append(", null"); }
                            if (drv["MaskValid"].ToString() != string.Empty && drv["DisplayName"].ToString() == "TextBox" && drv["DisplayMode"].ToString().ToLower() != "document") { sb.Append(", cREV" + drv["ColumnName"].ToString() + drv["TableId"].ToString()); }
							else { sb.Append(", null"); }
							if (drv["RangeValidType"].ToString() != string.Empty && drv["DisplayName"].ToString() == "TextBox") { sb.Append(", cRV" + drv["ColumnName"].ToString() + drv["TableId"].ToString()); }
							else { sb.Append(", null"); }
						}
						else { sb.Append(", null, null, null"); }
                        sb.Append(");" + Environment.NewLine);
                        if (drv["DisplayName"].ToString() == "Signature")
                        {
                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".HintMessage = ColumnWatermark(" + ii.ToString() + ");" + Environment.NewLine);
                        }
					}
					if (PopTextBox(drv))
					{
                        sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "E.Attributes[\"label_id\"] = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Label.ClientID; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "E.Attributes[\"target_id\"] = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ClientID;" + Environment.NewLine);
                    }
                    if (drv["DisplayMode"].ToString().ToLower() == "document")
                    {
                        sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pan.Height = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Height; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pan.Width = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Width;" + Environment.NewLine);
                    }
                    if (drv["DisplayMode"].ToString() == "AutoComplete")
                    {
                        if (drv["DdlFtrColumnId"].ToString() != string.Empty)
                        {
                            sb.Append("				Set" + drv["ColumnName"].ToString() + drv["TableId"] + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ",string.Empty,string.Empty);" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("				Set" + drv["ColumnName"].ToString() + drv["TableId"] + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ",string.Empty);" + Environment.NewLine);
                        }
                    }
					ii = ii + 1;
				}
			}
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				iOffset = ii;			// Save this for cFindButton
                //if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {sb.Append("				");} else {sb.Append("			");}
                //sb.Append("base.SetGridBehavior(c" + dw["ProgramName"].ToString() + "Grid, dtAuth, dtLabel, " + iOffset.ToString() + ");" + Environment.NewLine);
			}
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("			}" + Environment.NewLine);
				dv.RowFilter = "MasterTable = 'Y'";
				foreach (DataRowView drv in dv)
				{
					if (drv["DisplayMode"].ToString().ToLower() == "document")
					{
                        sb.Append("			if ((c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo.Attributes[\"OnClick\"] == null || c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) && c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo.Visible) {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
					}
                    else if (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton" && !string.IsNullOrEmpty(drv["ColumnId"].ToString()) && drv["DataTypeSqlName"].ToString().ToLower() != "varbinary")
                    {
                        sb.Append("			if ((c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Attributes[\"OnChange\"] == null || c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Attributes[\"OnChange\"].IndexOf(\"ChkPgDirty\") < 0) && c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo.Visible) {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Attributes[\"OnChange\"] += \"document.getElementById('\" + bPgDirty.ClientID + \"').value='Y'; ChkPgDirty();\";}" + Environment.NewLine);
                    }
                    else if (drv["ColumnIdentity"].ToString() != "Y" && (",Button,PlaceHolder,Label,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString())))
					{
						if (",CheckBox,RadioButtonList,Calendar,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sEvent = "OnClick"; } else { sEvent = "OnChange"; }
						sb.Append("			if ((c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes[\"" + sEvent + "\"] == null || c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes[\"" + sEvent + "\"].IndexOf(\"ChkPgDirty\") < 0) && c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Visible && ");
						if (drv["DisplayName"].ToString() == "TextBox")
						{
							sb.Append("!c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ReadOnly");
						}
						else
						{
							sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Enabled");
						}
						sb.Append(") {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes[\"" + sEvent + "\"] += \"document.getElementById('\" + bPgDirty.ClientID + \"').value='Y'; ChkPgDirty();");
                        if (drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y" || ",ComboBox,ComboBoxNoPunc,Calendar,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "upload")
						{
                            if (drv["IgnoreConfirm"].ToString() == "Y")
                            {
                                sb.Append("document.getElementById('\" + bConfirm.ClientID + \"').value='N';");
                            }
                            else sb.Append("return CanPostBack(true,this);");
                        }
                        if (",CheckBox,RadioButtonList,Calendar,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append(" this.focus();"); }
                        sb.Append("\";}");
                        if (drv["IgnoreConfirm"].ToString() != "Y")
                        {
                            sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes[\"NeedConfirm\"] = \"Y\";");
                        }
                        sb.Append(Environment.NewLine);
                    }
                    if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                    {
						sb.Append("			if (c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + (drv["DisplayName"].ToString() == "ImageButton" ? "" : "Search") + ".Attributes[\"OnClick\"] == null || c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + (drv["DisplayName"].ToString() == "ImageButton" ? "" : "Search") + ".Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + (drv["DisplayName"].ToString() == "ImageButton" ? "" : "Search") + ".Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
					}
					if (drv["PwdOvride"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
						sb.Append("			if (c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd.Attributes[\"OnChange\"] == null || c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd.Attributes[\"OnChange\"].IndexOf(\"_bConfirm\") < 0) {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd.Attributes[\"OnChange\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
					}
				}
			}
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("		private DataTable SetFunctionality(DataTable dt)" + Environment.NewLine);
            }
            else
            {
                sb.Append("		private void SetFunctionality()" + Environment.NewLine);
            }
            sb.Append("		{" + Environment.NewLine);
			sb.Append("			DataTable dtAuthRow = GetAuthRow();" + Environment.NewLine);
			sb.Append("			if (dtAuthRow != null)" + Environment.NewLine);
			sb.Append("			{" + Environment.NewLine);
			sb.Append("				DataRow dr = dtAuthRow.Rows[0];" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("				if (dr[\"AllowDel\"].ToString() == \"N\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					if ((bool)Session[KEY_bDeleteVisible]) {cDeleteButton.Visible = false; Session[KEY_bDeleteVisible] = false;}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("				else if ((bool)Session[KEY_bDeleteVisible]) {cDeleteButton.Visible = true; cDeleteButton.Enabled = true;}" + Environment.NewLine);
				sb.Append("				if ((dr[\"AllowUpd\"].ToString() == \"N\" && dr[\"AllowAdd\"].ToString() == \"N\") || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
                sb.Append("					cUndoAllButton.Visible = false; cSaveButton.Visible = false; cSaveCloseButton.Visible = false;" + Environment.NewLine);
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					sb.Append("					cShowImpButton.Visible = false;" + Environment.NewLine);
				}
				sb.Append("				}" + Environment.NewLine);
				sb.Append("				else" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                {
                    sb.Append("					cShowImpButton.Visible = dr[\"ViewOnly\"].ToString() != \"G\";" + Environment.NewLine);
                }
                sb.Append("					if ((bool)Session[KEY_bUndoAllVisible]) {cUndoAllButton.Visible = true; cUndoAllButton.Enabled = true;}" + Environment.NewLine);
                sb.Append("					if ((bool)Session[KEY_bUpdateVisible]) {cSaveButton.Visible = true; cSaveButton.Enabled = true;}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
                    sb.Append("				if ((dr[\"AllowAdd\"].ToString() == \"N\" && dr[\"AllowUpd\"].ToString() == \"N\") || dr[\"ViewOnly\"].ToString() == \"G\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\")) { cInsRowButton.Visible = false; }" + Environment.NewLine);
				}
				sb.Append("				if (dr[\"AllowAdd\"].ToString() == \"N\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					cNewButton.Visible = false; cNewSaveButton.Visible = false; cCopyButton.Visible = false; cCopySaveButton.Visible = false;" + Environment.NewLine);
                sb.Append("					if (dt != null && dt.Rows.Count > 0) {dt.Rows[0].Delete();}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("				else" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
                sb.Append("					if ((bool)Session[KEY_bNewVisible]) {cNewButton.Visible = true; cNewButton.Enabled = true;} else {cNewButton.Visible = false;}" + Environment.NewLine);
                sb.Append("					if ((bool)Session[KEY_bNewSaveVisible]) {cNewSaveButton.Visible = true; cNewSaveButton.Enabled = true;} else {cNewSaveButton.Visible = false;}" + Environment.NewLine);
                sb.Append("					if ((bool)Session[KEY_bCopyVisible]) {cCopyButton.Visible = true; cCopyButton.Enabled = true;} else {cCopyButton.Visible = false;}" + Environment.NewLine);
                sb.Append("					if ((bool)Session[KEY_bCopySaveVisible]) {cCopySaveButton.Visible = true; cCopySaveButton.Enabled = true;} else {cCopySaveButton.Visible = false;}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
                sb.Append("			return dt;" + Environment.NewLine);
            }
			else	// I3 Grid only.
			{
                sb.Append("				if (dr[\"AllowUpd\"].ToString() == \"N\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
                sb.Append("				{" + Environment.NewLine);
                sb.Append("					cShowImpButton.Visible = false;" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
                sb.Append("				if (dr[\"AllowAdd\"].ToString() == \"N\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\")) { cInsRowButton.Visible = false; }" + Environment.NewLine);
				sb.Append("				if ((dr[\"AllowDel\"].ToString() == \"N\" && dr[\"AllowUpd\"].ToString() == \"N\" && dr[\"AllowAdd\"].ToString() == \"N\") || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					cUndoAllButton.Visible = false; cSaveButton.Visible = false;" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("				else" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					if ((bool)Session[KEY_bUndoAllVisible]) {cUndoAllButton.Visible = true; cUndoAllButton.Enabled = true;}" + Environment.NewLine);
				sb.Append("					if ((bool)Session[KEY_bUpdateVisible]) {cSaveButton.Visible = true; cSaveButton.Enabled = true;}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
			}
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		protected void cFilterId_SelectedIndexChanged(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || (dt != null && UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"))))" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
			}
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("				cNewButton_Click(sender, new EventArgs());" + Environment.NewLine);
			}
			else
			{
				sb.Append("				Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, null);" + Environment.NewLine);
			}
			//sb.Append("				SavePreserve(cFilterId.SelectedValue,1);" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {sb.Append("			}" + Environment.NewLine);}
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		protected void cSystemId_SelectedIndexChanged(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			base.LCurr.DbId = byte.Parse(cSystemId.SelectedValue);" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || (dt != null && UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"))))" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
			}
            sb.Append("				Session[KEY_sysConnectionString] = SysConnectStr(byte.Parse(cSystemId.SelectedValue));" + Environment.NewLine);
            sb.Append("				Session[KEY_sysConnectionString + \"Pwd\"] = base.AppPwd(base.LCurr.DbId);" + Environment.NewLine);
            dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
				{
					sb.Append("				Session.Remove(KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ");" + Environment.NewLine);
				}
			}
			sb.Append("				GetCriteria(GetScrCriteria());" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("				cFilterId_SelectedIndexChanged(sender, e);" + Environment.NewLine);
			}
			else
			{
				sb.Append("				Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, null);" + Environment.NewLine);
			}
			//sb.Append("				SavePreserve(cSystemId.SelectedValue,2);" + Environment.NewLine);
			foreach (DataRowView drv in dv)
			{
                if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                {
                    //if (drv["DisplayMode"].ToString().ToLower() == "document")
                    //{
                    //    sb.Append("				if (c" + pMKeyColumn + ".Text != string.Empty) { c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Script(); }" + Environment.NewLine);
                    //}
                    //else
                    //{
						sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Script();" + Environment.NewLine);
					//}
				}
			}
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append("			}" + Environment.NewLine); }
			sb.Append("		}" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append(Environment.NewLine);
				sb.Append("		private void ClearMaster(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			DataTable dt = GetAuthCol();" + Environment.NewLine);
				dv.RowFilter = "MasterTable = 'Y'";
				ii = 0;
				foreach (DataRowView drv in dv)
				{
					if (drv["ColumnName"].ToString() != pMKey && ",Button,Label,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0)	// Do not clear Primary Key column.
					{
						if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
						{
							sb.Append("			if (dt.Rows[" + ii.ToString() + "][\"ColVisible\"].ToString() == \"Y\" && dt.Rows[" + ii.ToString() + "][\"ColReadOnly\"].ToString() != \"Y\") {");
                            if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
							{
								sb.Append("Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
								if (drv["DisplayMode"].ToString().ToLower() == "document") { sb.Append("GV,"); } else { sb.Append(","); }
                                sb.Append(Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()));
								if (drv["DdlFtrColumnId"].ToString() != string.Empty)
								{
									dvs.RowFilter = string.Empty;
									foreach (DataRowView drvs in dvs)
									{
										if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
										{
											if (drvs["MasterTable"].ToString() == "Y")
											{
												sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
												if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} 
												else {sb.Append("Text");}
											}
											else
											{
												sb.Append(",((" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\")).");
												if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} 
												else {sb.Append("Text");}
											}
										}
									}
								}
								sb.Append(");");
							}
                            else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
							{
								sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ClearSearch();");
							}
							else
							{
								sb.Append("Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
								if (drv["DisplayMode"].ToString().ToLower() == "document") { sb.Append("GV,string.Empty"); } else { sb.Append(",string.Empty"); }
								if (drv["DdlFtrColumnId"].ToString() != string.Empty)
								{
									dvs.RowFilter = string.Empty;
									foreach (DataRowView drvs in dvs)
									{
										if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
										{
											if (drvs["MasterTable"].ToString() == "Y")
											{
												sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
												if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} 
												else {sb.Append("Text");}
											}
											else
											{
												sb.Append(",((" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\")).");
												if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} 
												else {sb.Append("Text");}
											}
										}
									}
								}
								sb.Append(");");
							}
							if (drv["DisplayName"].ToString() != "ComboBox" && drv["ColPostBack"].ToString() == "Y") {sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectedIndexChanged(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ", new EventArgs());");}
							sb.Append("}" + Environment.NewLine);
						}
                        else if (drv["DdlRefColumnId"].ToString() == string.Empty && ",imagelink,imagepopup,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0)
                        {
                            sb.Append("			if (dt.Rows[" + ii.ToString() + "][\"ColVisible\"].ToString() == \"Y\" && dt.Rows[" + ii.ToString() + "][\"ColReadOnly\"].ToString() != \"Y\") {");
                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = ");
                            if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
                            {
                                sb.Append("\"" + Utils.AddTilde(drv["DefaultValue"].ToString()) + "\";");
                            }
                            else
                            {
                                sb.Append("\"~/images/Link.gif\";");
                            }
                            sb.Append(" }" + Environment.NewLine);
                        }
                        else if (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayMode"].ToString().ToLower() == "imagebutton")
                        {
                            sb.Append("			if (dt.Rows[" + ii.ToString() + "][\"ColVisible\"].ToString() == \"Y\" && dt.Rows[" + ii.ToString() + "][\"ColReadOnly\"].ToString() != \"Y\") {");
                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = ");
                            if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
                            {
                                sb.Append("\"" + Utils.AddTilde(drv["DefaultValue"].ToString()) + "\";");
                            }
                            else
                            {
                                sb.Append("\"~/images/DefaultImg.png\";");
                            }
                            if (!string.IsNullOrEmpty(drv["ColumnId"].ToString()) && drv["DataTypeSqlName"].ToString().ToLower() != "varbinary")
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Text = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl;");
                            }
                            sb.Append(" }" + Environment.NewLine);
                        }
                        else if ((drv["DdlRefColumnId"].ToString() == string.Empty || drv["DisplayMode"].ToString().ToLower() == "currency") && (",Button,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString())))
						{
							sb.Append("			if (dt.Rows[" + ii.ToString() + "][\"ColVisible\"].ToString() == \"Y\" && dt.Rows[" + ii.ToString() + "][\"ColReadOnly\"].ToString() != \"Y\") {");
							sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
                            if (",CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
							{
								sb.Append(".Checked = base.GetBool(");
                                if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y") { sb.Append("\"" + drv["DefaultValue"].ToString() + "\");"); } 
								else {sb.Append("\"N\");");}
							}
							else if (",Calendar,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
							{
                                if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
                                {
									sb.Append(".SelectedDate = ");
									try {DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("\"" + drv["DefaultValue"].ToString() + "\";");}
									catch {sb.Append(drv["DefaultValue"].ToString() + ";");}
								}
								else
								{
									sb.Append(".SelectedDates.Clear();");
								}
								sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".VisibleDate = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedDate;");
							}
                            else if (",Signature,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                            {
                                sb.Append(".ClearSignature();");
                            }
                            else
							{
								if (drv["DisplayName"].ToString() == "Editor") { sb.Append(".Content = "); }
                                else { sb.Append(".Text = "); }
                                if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
                                {
									if (",LongDate,".IndexOf(","+drv["DisplayMode"].ToString()+",") >= 0)
									{
										try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToLongDateString();"); }
										catch {sb.Append(drv["DefaultValue"].ToString() + ".ToLongDateString();");}
									}
                                    else if (",LongDateTime,LongDateTimeUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                                    {
                                        try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"f\");"); }
                                        catch { sb.Append(drv["DefaultValue"].ToString() + ".ToString(\"f\");"); }
                                    }
                                    else if (",ShortDateTime,ShortDateTimeUTC,DateTime,DateTimeUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                                    {
                                        try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"g\");"); }
                                        catch { sb.Append(drv["DefaultValue"].ToString() + ".ToString(\"g\");"); }
                                    }
                                    else if (",ShortDate,Date,DateUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                                    {
                                        try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToShortDateString();"); }
                                        catch { sb.Append(drv["DefaultValue"].ToString() + ".ToShortDateString();"); }
                                    }
                                    else
                                    {
                                        sb.Append(Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()) + ";");
									}
									if (drv["ColPostBack"].ToString() == "Y") {sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged(sender, e);");}
								}
								else
								{
									sb.Append("string.Empty;");
								}
							}
							sb.Append("}" + Environment.NewLine);
						}
					}
					ii = ii + 1;
				}
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "DEFVAL")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** Default Value (Folder) Web Rule starts here *** //" + Environment.NewLine); }
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		private void InitMaster(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				dv.RowFilter = "MasterTable = 'Y'";
				foreach (DataRowView drv in dv)
				{
                    if (",Button,Label,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0)
                    {
                        if (drv["ColumnIdentity"].ToString() != "Y" 
                            && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 
                                || drv["DisplayMode"].ToString().ToLower() == "document")
                            )
					    {
						    sb.Append("			");
                            if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
                            {
							    sb.Append("Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ",");
                                sb.Append(Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()));
							    if (drv["DdlFtrColumnId"].ToString() != string.Empty)
							    {
								    dvs.RowFilter = string.Empty;
								    foreach (DataRowView drvs in dvs)
								    {
									    if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
									    {
										    if (drvs["MasterTable"].ToString() == "Y")
										    {
											    sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
											    if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} 
											    else {sb.Append("Text");}
										    }
										    else
										    {
											    sb.Append(",((" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\")).");
											    if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} 
											    else {sb.Append("Text");}
										    }
									    }
								    }
							    }
							    //if (drv["DisplayName"].ToString() == "ComboBox") {sb.Append(",false");}
							    sb.Append(");");
						    }
                            else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
						    {
							    sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ClearSearch();");
						    }
						    else
						    {
							    //if (drv["DisplayMode"].ToString().ToLower() == "document") { sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text = string.Empty; "); }
							    sb.Append("Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
							    if (drv["DisplayMode"].ToString().ToLower() == "document") { sb.Append("GV"); }
							    sb.Append(",string.Empty");
							    if (drv["DdlFtrColumnId"].ToString() != string.Empty)
							    {
								    dvs.RowFilter = string.Empty;
								    foreach (DataRowView drvs in dvs)
								    {
									    if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
									    {
										    if (drvs["MasterTable"].ToString() == "Y")
										    {
											    sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
											    if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} 
											    else {sb.Append("Text");}
										    }
										    else
										    {
											    sb.Append(",((" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\")).");
											    if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} 
											    else {sb.Append("Text");}
										    }
									    }
								    }
							    }
							    sb.Append(");");
						    }
						    if (drv["DisplayName"].ToString() != "ComboBox" && drv["ColPostBack"].ToString() == "Y") {sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectedIndexChanged(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ", new EventArgs());");}
					    }
                        else if (drv["DdlRefColumnId"].ToString() == string.Empty && ",imagelink,imagepopup,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0)
                        {
                            if (drv["DefaultValue"].ToString() != string.Empty && !string.IsNullOrEmpty(drv["HyperLinkUrl"].ToString()))
                            {
                                sb.Append("			c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = \"" + Utils.AddTilde(drv["DefaultValue"].ToString()) + "\";");
                            }
                            else     // Do not use Link.gif and ".ImageUrl=string.Empty" is no good.
                            {
                                sb.Append("			c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Visible = false;");
                            }
                        }
                        else if (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton")
                        {
                            sb.Append("			c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = \"");
                            if (drv["DefaultValue"].ToString() != string.Empty)
                            {
                                sb.Append(Utils.AddTilde(drv["DefaultValue"].ToString()) + "\";");
                            }
                            else
                            {
                                sb.Append("~/images/DefaultImg.png\";");
                            }
                            if (!string.IsNullOrEmpty(drv["ColumnId"].ToString()) && drv["DataTypeSqlName"].ToString().ToLower() != "varbinary")
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Text = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl;");
                            }
                        }
                        else if ((drv["DdlRefColumnId"].ToString() == string.Empty || drv["DisplayMode"].ToString().ToLower() == "currency") && (",Button,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString())))
					    {
						    sb.Append("			");
						    sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
                            if (",CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
						    {
							    sb.Append(".Checked = base.GetBool(");
                                if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y") { sb.Append("\"" + drv["DefaultValue"].ToString() + "\");"); }
                                else { sb.Append("\"N\");"); }
						    }
						    else if (",Calendar,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						    {
                                if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
                                {
								    sb.Append(".SelectedDate = ");
								    try {DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("\"" + drv["DefaultValue"].ToString() + "\";");}
								    catch {sb.Append(drv["DefaultValue"].ToString() + ";");}
							    }
							    else
							    {
								    sb.Append(".SelectedDates.Clear();");
							    }
							    sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".VisibleDate = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedDate;");
						    }
                            else if (",Signature,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                            {
                                sb.Append(".ClearSignature();");
                            }
                            else
                            {
                                if (drv["DisplayName"].ToString() == "Editor") { sb.Append(".Content = "); }
                                else { sb.Append(".Text = "); }
                                if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
                                {
                                    if (",LongDate,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                                    {
                                        try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToLongDateString();"); }
                                        catch { sb.Append(drv["DefaultValue"].ToString() + ".ToLongDateString();"); }
                                    }
                                    else if (",LongDateTime,LongDateTimeUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                                    {
                                        try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"f\");"); }
                                        catch { sb.Append(drv["DefaultValue"].ToString() + ".ToString(\"f\");"); }
                                    }
                                    else if (",ShortDateTime,ShortDateTimeUTC,DateTime,DateTimeUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                                    {
                                        try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"g\");"); }
                                        catch { sb.Append(drv["DefaultValue"].ToString() + ".ToString(\"g\");"); }
                                    }
                                    else if (",ShortDate,Date,DateUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                                    {
                                        try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToShortDateString();"); }
                                        catch { sb.Append(drv["DefaultValue"].ToString() + ".ToShortDateString();"); }
                                    }
                                    else
                                    {
                                        sb.Append(Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()) + ";");
                                    }
                                    if (drv["ColPostBack"].ToString() == "Y") { sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged(sender, e);"); }
                                }
                                else
                                {
                                    sb.Append("string.Empty;");
                                }
                            }
					    }
                        if (!string.IsNullOrEmpty(drv["HyperLinkUrl"].ToString()))   // Static Link URL.
                        {
                            sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Style.Value = \"cursor:pointer;\";");
                            if (drv["HyperLinkUrl"].ToString().ToLower().StartsWith("javascript:"))
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes.Add(\"OnClick\",\"" + drv["HyperLinkUrl"].ToString().Substring(drv["HyperLinkUrl"].ToString().ToLower().IndexOf("javascript:") + 11) + "\");");
                            }
                            else if (",HyperPopUp,ImagePopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 && !drv["HyperLinkUrl"].ToString().ToLower().StartsWith("mailto"))
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes.Add(\"OnClick\",\"SearchLink('" + drv["HyperLinkUrl"].ToString() + "','','',''); return stopEvent(this,event);\");");
                            }
                            else
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".NavigateUrl = \"" + Utils.AddTilde(drv["HyperLinkUrl"].ToString()) + "\";");
                            }
                        }
                        sb.Append(Environment.NewLine);
                    }
				}
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "DEFVAL")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** Default Value (Folder) Web Rule starts here *** //" + Environment.NewLine); }
				sb.Append("		}" + Environment.NewLine);
				sb.Append("		protected void c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_TextChanged(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)sender).FocusID);" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		protected void c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_DDFindClick(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)sender).FocusID);" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		protected void c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_SelectedIndexChanged(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
                sb.Append("			InitMaster(sender, e);      // Do this first to enable defaults for non-database columns." + Environment.NewLine);
                sb.Append("			DataTable dt = null;" + Environment.NewLine);
				sb.Append("			try" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
                sb.Append("				dt = (new AdminSystem()).GetMstById(\"Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById\"," + dtLis.Rows[0]["Calling2Params"].ToString() + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
                sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
				sb.Append("			if (dt != null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				CheckAuthentication(false);" + Environment.NewLine);
                if ("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append("			    SetFunctionality();" + Environment.NewLine); }
                sb.Append("				if (dt.Rows.Count > 0)" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SetDdVisible();" + Environment.NewLine);
				sb.Append("					DataRow dr = dt.Rows[0];" + Environment.NewLine);
				dv.RowFilter = "MasterTable = 'Y'";
				foreach (DataRowView drv in dv)
				{
					if (drv["TableId"].ToString() != string.Empty)
					{
						if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
						{
							sb.Append("					Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
							if (drv["DisplayMode"].ToString().ToLower() == "document") { sb.Append("GV,string.Empty"); }
							else if (",DataGrid,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0) {sb.Append(",string.Empty");}
							else {sb.Append(",dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()");}
							if (drv["DdlFtrColumnId"].ToString() != string.Empty)
							{
								dvs.RowFilter = string.Empty;
								foreach (DataRowView drvs in dvs)
								{
									if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
									{
										if (drvs["MasterTable"].ToString() == "Y")
										{
											sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
											if (",ComboBox,DropDownList,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} 
											else {sb.Append("Text");}
										}
										else
										{
											sb.Append(",((" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\")).");
											if (",ComboBox,DropDownList,RadioButtonList,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0) { sb.Append("SelectedValue"); } 
											else {sb.Append("Text");}
										}
									}
								}
							}
                            if (("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 || ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")) && drv["DisplayName"].ToString() == "ComboBox")
                            {
                                sb.Append(", c" + dw["ProgramName"].ToString() + "Grid.EditItem");
                            }
                            sb.Append(");");
                            if (drv["ColPostBack"].ToString() == "Y") { sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectedIndexChanged(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ", new EventArgs());"); }
                            if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y" && (drv["DisplayName"].ToString() == "DropDownList" || (drv["AllowNulls"].ToString() == "Y" && drv["RequiredValid"].ToString() == "N" && drv["DisplayMode"].ToString() != "Document")))
							{
								sb.Append(" if (c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedIndex <= 0 && !(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Enabled && c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Visible)) { Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ",");
                                sb.Append(Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()));
                                if (drv["DdlFtrColumnId"].ToString() != string.Empty)
                                {
                                    dvs.RowFilter = string.Empty;
                                    foreach (DataRowView drvs in dvs)
                                    {
                                        if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
                                        {
                                            if (drvs["MasterTable"].ToString() == "Y")
                                            {
                                                sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
                                                if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0) { sb.Append("SelectedValue"); }
                                                else { sb.Append("Text"); }
                                            }
                                            else
                                            {
                                                sb.Append(",((" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\")).");
                                                if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0) { sb.Append("SelectedValue"); }
                                                else { sb.Append("Text"); }
                                            }
                                        }
                                    }
                                }
                                sb.Append("); }");
                            }
							sb.Append(Environment.NewLine);
						}
                        else if (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton")
                        {
                            string pKeyDbAppDatabase = (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".");
                            string pKeySystemId = drv["SystemId"].ToString();

                            if (drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                            {
                                sb.Append("					try { if (dr[\"" + drv["ColName"].ToString() + drv["TableId"].ToString() + "\"].Equals(System.DBNull.Value)) { c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = ");
                                if (drv["DefaultValue"].ToString() != string.Empty)
                                {
                                    sb.Append("\"" + Utils.AddTilde(drv["DefaultValue"].ToString()) + "\"; }");
                                }
                                else
                                {
                                    sb.Append("\"~/images/DefaultImg.png\"; }");
                                }
                                sb.Append(" else { c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".OnClientClick = \"window.open('\" + GetUrlWithQSHash(\"DnLoad.aspx?key=\" + dr[\"" + pMKey + drv["TableId"].ToString() + "\"].ToString() + \"&tbl=dbo." + drv["TableName"].ToString() + "&knm=" + pMKey + "&col=" + drv["ColumnName"].ToString() + (string.IsNullOrEmpty(drv["ResizeHeight"].ToString()) ? string.Empty : "&hgt=" + drv["ResizeHeight"].ToString()) + (string.IsNullOrEmpty(drv["ResizeWidth"].ToString()) ? string.Empty : "&wth=" + drv["ResizeWidth"].ToString()) + "&sys=" + pKeySystemId + "\") + \"'); return false;\"; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = RO.Common3.Utils.BlobPlaceHolder(dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] as byte[],true);}");
                            }
                            else
                            {
                                sb.Append("					try { c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = RO.Common3.Utils.AddTilde(GetUrlWithQSHash(dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()));");
                            }
                            if (drv["ColPostBack"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y")
                            {
                                if (drv["DataTypeSqlName"].ToString().ToLower() != "varbinary")
                                {
                                    sb.Append("	c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Text = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl;");
                                }
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click(sender, new ImageClickEventArgs(0, 0));");
                            }
                            sb.Append(" }" + Environment.NewLine);
                            sb.Append("					catch { c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = string.Empty; }" + Environment.NewLine);
                        }
                        else if ((drv["DdlRefColumnId"].ToString() == string.Empty || drv["DisplayMode"].ToString().ToLower() == "currency") && (",Button,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString())))
						{
							sb.Append("					try {");
                            if (drv["DisplayName"].ToString() == "Signature")
                            {
                                sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SignatureData = dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] as byte[];} catch {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SignatureData = null;}" + Environment.NewLine);
                            }
                            else if (drv["DisplayName"].ToString() == "CheckBox")
							{
								sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Checked = base.GetBool(dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString());} catch {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Checked = false;}" + Environment.NewLine);
							}
							else if (drv["DisplayName"].ToString() == "Calendar")
							{
								sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedDate = DateTime.Parse(dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString());} catch {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedDates.Clear();}" + Environment.NewLine);
								sb.Append("					c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".VisibleDate = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedDate;" + Environment.NewLine);
							}
							else
							{
                                sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
								if (drv["DisplayName"].ToString() == "Editor") { sb.Append(".Content = "); }
                                else { sb.Append(".Text = "); }
                                if (drv["DisplayMode"].ToString().ToLower() == "currency")
                                {
                                    sb.Append("base.fxCurrency(dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()");
                                    sb.Append(string.IsNullOrEmpty(drv["DdlKeyColumnName"].ToString()) ? ",base.LUser.Culture" : ",dr[\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "\"].ToString()");
                                    sb.Append(string.IsNullOrEmpty(drv["DdlRefColumnName"].ToString()) ? ",base.LUser.Culture)" : ",dr[\"" + drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString() + "\"].ToString())");
                                }
                                else
                                {
                                    sb.Append(Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), true) + "dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()" + Robot.DataTypeConvert(string.Empty, drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), string.Empty, false));
                                }
                                sb.Append(";");
                                if (drv["ColPostBack"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y")
                                {
                                    sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged(sender, e);");
                                }
                                sb.Append("} catch {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
								if (drv["DisplayName"].ToString() == "Editor") { sb.Append(".Content = "); }
                                else { sb.Append(".Text = "); }
								sb.Append("string.Empty;}" + Environment.NewLine);
							}
						}
					}
                    else if (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton")
                    {
                        sb.Append("					c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = ");
                        if (drv["DefaultValue"].ToString() != string.Empty)
                        {
                            sb.Append("\"" + Utils.AddTilde(drv["DefaultValue"].ToString()) + "\";" + Environment.NewLine);
                        }
                        else
                        {
                            sb.Append("\"~/images/DefaultImg.png\";" + Environment.NewLine);
                        }
                    }
                    if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        // Do not show link if no url.
                        sb.Append("					if (string.IsNullOrEmpty(");
                        if (!string.IsNullOrEmpty(drv["HyperLinkUrl"].ToString()))
                        {
                            sb.Append("\"" + drv["HyperLinkUrl"].ToString() + "\"");
                        }
                        else
                        {
                            sb.Append("dr[\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "URL\"].ToString()");
                        }
                        sb.Append(")) {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Visible = false;}" + Environment.NewLine);
                        sb.Append("					else" + Environment.NewLine);
                        sb.Append("					{" + Environment.NewLine);
                        sb.Append("						c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Visible = true;" + Environment.NewLine);
                        if (!string.IsNullOrEmpty(drv["HyperLinkUrl"].ToString()))   // Static Link URL override Key Column.
                        {
                            sb.Append("						c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Style.Value = \"cursor:pointer;\";");
                            if (drv["HyperLinkUrl"].ToString().ToLower().StartsWith("javascript:"))
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes.Add(\"OnClick\",\"" + drv["HyperLinkUrl"].ToString().Substring(drv["HyperLinkUrl"].ToString().ToLower().IndexOf("javascript:") + 11) + "\");");
                            }
                            else if (",HyperPopUp,ImagePopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 && !drv["HyperLinkUrl"].ToString().ToLower().StartsWith("mailto"))
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes.Add(\"OnClick\",\"SearchLink('" + drv["HyperLinkUrl"].ToString() + "','','',''); return stopEvent(this,event);\");");
                            }
                            else
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".NavigateUrl = \"" + Utils.AddTilde(drv["HyperLinkUrl"].ToString()) + "\";");
                            }
                            sb.Append(Environment.NewLine);
                        }
                        else if (drv["DdlKeyColumnName"].ToString() != string.Empty && drv["DdlKeyTableId"].ToString() != string.Empty)  // Dynamic URL present.
                        {
                            sb.Append("						if (dr[\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "URL\"].ToString() == string.Empty) {");
                            if (",HyperPopUp,ImagePopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 && !drv["HyperLinkUrl"].ToString().ToLower().StartsWith("mailto"))
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes.Remove(\"onclick\"); }" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".NavigateUrl = string.Empty; }" + Environment.NewLine);
                            }
                            sb.Append("						else { c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Style.Value = \"cursor:pointer;\";");
                            if (",HyperPopUp,ImagePopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 && !drv["HyperLinkUrl"].ToString().ToLower().StartsWith("mailto"))
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Attributes.Add(\"OnClick\",\"SearchLink('\" + dr[\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "URL\"].ToString() + \"','','',''); return stopEvent(this,event);\"); }" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append(" c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".NavigateUrl = Utils.AddTilde(GetUrlWithQSHash(dr[\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "URL\"].ToString())); }" + Environment.NewLine);
                            }
                        }
                        // Display:
                        if (",HyperLink,HyperPopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            if (!string.IsNullOrEmpty(drv["DefaultValue"].ToString()))
                            {
                                sb.Append("					    try {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text = \"" + drv["DefaultValue"].ToString() + "\";} catch {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text = string.Empty;}" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("					    try {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text = dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString();} catch {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text = string.Empty;}" + Environment.NewLine);
                            }
                        }
                        else if (",ImageLink,ImagePopUp,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            if (!string.IsNullOrEmpty(drv["DefaultValue"].ToString()))
                            {
                                sb.Append("					    try {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = \"" + Utils.AddTilde(drv["DefaultValue"].ToString()) + "\";} catch {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = string.Empty;}" + Environment.NewLine);
                            }
                            else if (drv["ColumnId"].ToString() == drv["DdlKeyColumnId"].ToString())
                            {
                                sb.Append("					    c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = \"~/images/Link.gif\";" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("					    try {");
                                sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = Utils.AddTilde(GetUrlWithQSHash(dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()));");
                                sb.Append("} catch {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ImageUrl = string.Empty;}" + Environment.NewLine);
                            }
                        }
                        sb.Append("					}" + Environment.NewLine);
                    }
                    if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                    {
						sb.Append("					c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Script();" + Environment.NewLine);
					}
				}
				sb.Append("				}" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
                foreach (DataRowView drv in dv)
                {
                    if (drv["DisplayMode"].ToString().ToLower() == "tokeninput")
                    {
                        sb.Append("			ScriptManager.RegisterStartupScript(this, this.GetType(), \"Ti" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\", @\"<script>Sys.Application.add_load(function(){ try { $('#\" + c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ClientID + @\"').tokenInput([], { theme:'tokenInput', preventDuplicates:true })");
                        if (!string.IsNullOrEmpty(drv["ColumnHeight"].ToString())) { sb.Append(".parent().find('ul').css('height','" + drv["ColumnHeight"].ToString() + "px')"); }
                        sb.Append(";");
                        if (!string.IsNullOrEmpty(drv["ColumnSize"].ToString()))
                        {
                            try
                            {
                                sb.Append(" $('#\" + c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ClientID + @\"').parent().find('.token-input-list-tokenInput').css('width','" + (int.Parse(drv["ColumnSize"].ToString()) + 6).ToString() + "px');");
                            }
                            catch { }
                        }
                        sb.Append(" } catch (er) {} });</script>\", false);" + Environment.NewLine);
                    }
                }
                sb.Append("			cButPanel.DataBind();");
                // In the case when Only Update is allowed and there is no data available for update:
                //if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append(" if (!cSaveButton.Visible) { cInsRowButton.Visible = false; } else { cInsRowButton.Visible = (bool)Session[KEY_bUpdateVisible]; }"); }
                if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append(" if (!cSaveButton.Visible) { cInsRowButton.Visible = false; }"); }
                sb.Append(Environment.NewLine);
                //sb.Append("			if (dt == null || dt.Rows.Count <= 0) {InitMaster(sender, e);}" + Environment.NewLine);
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					sb.Append("			DataTable dt" + dw["ProgramName"].ToString() + "Grid = null;" + Environment.NewLine);
                    sb.Append("			int filterId = 0; if (Utils.IsInt(cFilterId.SelectedValue)) { filterId = int.Parse(cFilterId.SelectedValue); }" + Environment.NewLine);
                    sb.Append("			try" + Environment.NewLine);
					sb.Append("			{" + Environment.NewLine);
                    sb.Append("				dt" + dw["ProgramName"].ToString() + "Grid = (new AdminSystem()).GetDtlById(" + screenId.ToString() + ",\"Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById\"," + dtDtl.Rows[0]["Calling2Params"].ToString() + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",filterId,base.LImpr,base.LCurr);" + Environment.NewLine);
					sb.Append("			}" + Environment.NewLine);
                    sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                    //sb.Append("			if (!dt" + dw["ProgramName"].ToString() + "Grid.Columns.Contains(\"_CurRow\")) { dt" + dw["ProgramName"].ToString() + "Grid.Columns.Add(\"_CurRow\"); }" + Environment.NewLine);
                    sb.Append("			if (!dt" + dw["ProgramName"].ToString() + "Grid.Columns.Contains(\"_NewRow\")) { dt" + dw["ProgramName"].ToString() + "Grid.Columns.Add(\"_NewRow\"); }" + Environment.NewLine);
                    sb.Append("			Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dt" + dw["ProgramName"].ToString() + "Grid;" + Environment.NewLine);
					sb.Append("			c" + dw["ProgramName"].ToString() + "Grid.EditIndex = -1;" + Environment.NewLine);
                    sb.Append("			c" + dw["ProgramName"].ToString() + "GridDataPager.PageSize = Int16.Parse(cPgSize.Text); GotoPage(0);" + Environment.NewLine);
                    sb.Append("			if (Session[KEY_lastSortCol] != null)" + Environment.NewLine);
                    sb.Append("			{" + Environment.NewLine);
                    sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_OnSorting(sender, new ListViewSortEventArgs((string)Session[KEY_lastSortExp], SortDirection.Ascending));" + Environment.NewLine);
                    sb.Append("			}" + Environment.NewLine);
                    sb.Append("			else if (dt" + dw["ProgramName"].ToString() + "Grid.Rows.Count <= 0 || (!((GetAuthRow().Rows[0][\"AllowUpd\"].ToString() == \"N\" || GetAuthRow().Rows[0][\"ViewOnly\"].ToString() == \"G\") && GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"N\") && !(Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\") && dt" + dw["ProgramName"].ToString() + "Grid.Rows.Count == 1))" + Environment.NewLine);
                    sb.Append("			{" + Environment.NewLine);
					sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_DataBind(dt" + dw["ProgramName"].ToString() + "Grid.DefaultView);" + Environment.NewLine);
                    sb.Append("			}" + Environment.NewLine);
                    sb.Append("			cFindButton_Click(sender, e);" + Environment.NewLine);
                    sb.Append("			cNaviPanel.Visible = true; cImportPwdPanel.Visible = false; Session.Remove(KEY_scrImport);" + Environment.NewLine);
				}
				sb.Append("			ScriptManager.GetCurrent(Parent.Page).SetFocus(c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.FocusID);" + Environment.NewLine);
				sb.Append("			ShowDirty(false); PanelTop.Update();" + Environment.NewLine);
                foreach (DataRowView drv in dv)
                {

                    if (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton" && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                    {
                        sb.Append("			c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Fi.Attributes[\"onchange\"] = \"if('\" + c" + pMKeyColumn + ".Text + \"'==''){PopDialog('','Please save the record first before upload','');}else{sendFile(this.files[0],'\" + GetUrlWithQSHash(\"UpLoad.aspx?key=\" + c" + pMKeyColumn + ".Text + \"&tbl=dbo." + drv["TableName"].ToString() + "&knm=" + pMKey + "&col=" + drv["ColumnName"].ToString() + (string.IsNullOrEmpty(drv["ResizeHeight"].ToString()) ? string.Empty : "&hgt=" + drv["ResizeHeight"].ToString()) + (string.IsNullOrEmpty(drv["ResizeWidth"].ToString()) ? string.Empty : "&wth=" + drv["ResizeWidth"].ToString()) + "&sys=\" + base.LCurr.SystemId.ToString()) + \"',refreshUploadCallback(this,'\" + c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ClientID + \"')); return false;}\";" + Environment.NewLine);
                        sb.Append("			c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Del.Attributes[\"onclick\"] = \"sendFile('','\" + GetUrlWithQSHash(\"UpLoad.aspx?del=true&key=\" + c" + pMKeyColumn + ".Text + \"&tbl=dbo." + drv["TableName"].ToString() + "&knm=" + pMKey + "&col=" + drv["ColumnName"].ToString() + (string.IsNullOrEmpty(drv["ResizeHeight"].ToString()) ? string.Empty : "&hgt=" + drv["ResizeHeight"].ToString()) + (string.IsNullOrEmpty(drv["ResizeWidth"].ToString()) ? string.Empty : "&wth=" + drv["ResizeWidth"].ToString()) + "&sys=\" + base.LCurr.SystemId.ToString()) + \"',refreshUploadCallback(this,'\" + c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ClientID + \"'));return false;\";" + Environment.NewLine);
                    }
                }
                bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "ENLSSE")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** List Selection (End of) Web Rule starts here *** //" + Environment.NewLine); }
				sb.Append("		}" + Environment.NewLine);
			}
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				dv.RowFilter = "MasterTable = 'Y'";
				foreach (DataRowView drv in dv)
				{
					if (drv["ColumnIdentity"].ToString() != "Y" && (",DataGrid,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
					{
						cName = Robot.GetControlName(drv);
						sb.Append(Environment.NewLine);
						if (drv["DisplayMode"].ToString().ToLower() == "document")
						{
                            string altUpdDocFunction = string.IsNullOrEmpty(drv["MaskValid"].ToString()) ? null : drv["MaskValid"].ToString();
							sb.Append("		protected void c" + cName + "GV_PageIndexChanged(object sender, GridViewPageEventArgs e)" + Environment.NewLine);
							sb.Append("		{" + Environment.NewLine);
							sb.Append("			c" + cName + "GV.PageIndex = e.NewPageIndex;" + Environment.NewLine);
							sb.Append("			c" + cName + "GV.DataSource = ((DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "]).DefaultView; c" + cName + "GV.DataBind();" + Environment.NewLine);
							sb.Append("		}" + Environment.NewLine);
							sb.Append(Environment.NewLine);
							sb.Append("		protected void c" + cName + "GV_RowCommand(object sender, GridViewCommandEventArgs e)" + Environment.NewLine);
							sb.Append("		{" + Environment.NewLine);
							sb.Append("			if (e.CommandName == \"deleterow\" && c" + pMKeyColumn + ".Text != string.Empty)" + Environment.NewLine);
							sb.Append("			{" + Environment.NewLine);
							sb.Append("				try" + Environment.NewLine);
							sb.Append("				{" + Environment.NewLine);
                            sb.Append("					" + (altUpdDocFunction ?? "(new AdminSystem()).DelDoc") + "(c" + pMKeyColumn + ".Text, e.CommandArgument.ToString(), base.LUser.UsrId.ToString(), \"" + drv["DdlKeyTableName"] + "\", \"" + drv["TableName"] + "\", \"" + drv["ColumnName"] + "\", \"" + pMKey + "\"" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ");" + Environment.NewLine);
                            sb.Append("				}" + Environment.NewLine);
                            sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
							sb.Append("				Session.Remove(KEY_dt" + cName + "); Set" + cName + "(c" + cName + "GV, string.Empty);" + Environment.NewLine);
							sb.Append("			}" + Environment.NewLine);
							sb.Append("		}" + Environment.NewLine);
						}
						else
						{
							sb.Append("		protected void c" + cName + "_PageIndexChanged(object sender, DataGridPageChangedEventArgs e)" + Environment.NewLine);
							sb.Append("		{" + Environment.NewLine);
							sb.Append("			c" + cName + ".CurrentPageIndex = e.NewPageIndex;" + Environment.NewLine);
                            sb.Append("			DataView dv = ((DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "]).DefaultView;dv.RowFilter = ViewState[\"" + drv["ColumnName"].ToString() + "_RowFilter\"] as string;" + Environment.NewLine);
                            sb.Append("			c" + cName + ".DataSource = dv; c" + cName + ".DataBind();" + Environment.NewLine);
                            sb.Append("		}" + Environment.NewLine);
						}
					}
					if ((drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y" || drv["ColumnLink"].ToString() != string.Empty) && drv["ColumnIdentity"].ToString() != "Y" && ",CheckBox,Calendar,TextBox,ComboBox,DropDownList,ListBox,RadioButtonList,Button,ImageButton,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
						sb.Append(Environment.NewLine);
						if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							if (drv["DisplayName"].ToString() == "ComboBox")
							{
								sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged(object sender, System.EventArgs e)" + Environment.NewLine);
								sb.Append("		{" + Environment.NewLine);
								sb.Append("			ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)sender).FocusID);" + Environment.NewLine);
								sb.Append("		}" + Environment.NewLine);
								sb.Append(Environment.NewLine);
								sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_DDFindClick(object sender, System.EventArgs e)" + Environment.NewLine);
								sb.Append("		{" + Environment.NewLine);
								sb.Append("			ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)sender).FocusID);" + Environment.NewLine);
								sb.Append("		}" + Environment.NewLine);
								sb.Append(Environment.NewLine);
							}
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectedIndexChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						else if (",CheckBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_CheckedChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						else if (",Calendar,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectionChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						else if (",Button,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						else if (",ImageButton,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click(object sender, System.Web.UI.ImageClickEventArgs e)" + Environment.NewLine);
						}
                        //else if (",Rating,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        //{
                        //    sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Changed(object sender, System.EventArgs e)" + Environment.NewLine);
                        //}
                        else
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						sb.Append("		{" + Environment.NewLine);
						bWebRule = false;
						foreach (DataRowView drvr in dvWRule)
						{
							if (drvr["EventCode"].ToString() == "SELCHG" && drv["ScreenObjId"].ToString() == drvr["ScreenObjId"].ToString())
							{
								bWebRule = true;
								sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
								sb.Append(WrapConditionalWebRule("   ", drvr));
							}
						}
                        if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** On Change/ On Click Web Rule starts here *** //" + Environment.NewLine); }
                        sb.Append("			EnableValidators(true); // Do not remove; Need to reenable after postback, especially in the grid." + Environment.NewLine);
                        if (",Button,ImageButton,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0)
						{
							if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
							{
								sb.Append("			TextBox pwd = null;" + Environment.NewLine);
                                sb.Append("			if (c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Items.Count > 0");
                                if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                                    sb.Append(" && c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".DataSource != null)" + Environment.NewLine);
                                else
                                    sb.Append(" && Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "] != null)" + Environment.NewLine);
                                sb.Append("			{" + Environment.NewLine);
                                if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                                    sb.Append("				DataView dv = (DataView) c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".DataSource; dv.RowFilter = string.Empty;" + Environment.NewLine);
                                else if (",DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
								{
                                    sb.Append("				DataView dv = ((DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "]).DefaultView; dv.RowFilter = string.Empty;" + Environment.NewLine);
								}
								if (",ComboBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
                                {
                                    sb.Append("				DataRowView dr = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".DataSetIndex >= 0 && c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".DataSetIndex < dv.Count ? dv[c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".DataSetIndex] : dv[0];" + Environment.NewLine);
                                }
                                else
                                {
                                    sb.Append("				DataRowView dr = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedIndex >= 0 && c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedIndex < dv.Count ? dv[c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedIndex] : dv[0];" + Environment.NewLine);
                                }
								if (drv["PwdOvride"].ToString() == "Y")
								{
									sb.Append("				try" + Environment.NewLine);
									sb.Append("				{" + Environment.NewLine);
                                    sb.Append("					if ((dv.Table.Columns.Contains(\"OvrideId\") && dr[\"OvrideId\"].ToString() != string.Empty) && (dr[\"PromptAlways\"].ToString() == \"Y\" || !(new AdminSystem()).IsValidOvride(new Credential(dr[\"OvrideId\"].ToString(),string.Empty),base.LUser.UsrId,LcSysConnString,LcAppPw)))" + Environment.NewLine);
                                    sb.Append("					{" + Environment.NewLine);
                                    sb.Append("						c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Visible = false; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd.Visible = true; pwd = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd;" + Environment.NewLine);
                                    sb.Append("					}" + Environment.NewLine);
									sb.Append("				}" + Environment.NewLine);
                                    sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
								}
								dvs.RowFilter = "MasterTable = 'Y'";
								foreach (DataRowView drvs in dvs)
								{
									if (drv["ColumnId"].ToString() == drvs["DdlRefColumnId"].ToString())
									{
										if (",CheckBox,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0)
										{
											sb.Append("				c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".Checked = base.GetBool(dr[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString());" + Environment.NewLine);
										}
                                        else if (",ImageButton,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0)  // Do not check "drv["DdlRefColumnId"].ToString() == string.Empty":
                                        {
                                            if (drvs["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                                            {
                                                sb.Append("				try { if (dr[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].Equals(System.DBNull.Value)) { c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".ImageUrl = ");
                                                if (drvs["DefaultValue"].ToString() != string.Empty)
                                                {
                                                    sb.Append("\"" + Utils.AddTilde(drvs["DefaultValue"].ToString()) + "\"; }");
                                                }
                                                else
                                                {
                                                    sb.Append("\"~/images/DefaultImg.png\"; }");
                                                }
                                                sb.Append(" else { c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".ImageUrl = RO.Common3.Utils.BlobPlaceHolder(dr[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"] as byte[], true);}} catch { c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".ImageUrl = string.Empty; }" + Environment.NewLine);
                                            }
                                            else
                                            {
                                                sb.Append("				try {if (dr[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString()  == string.Empty) { c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".Visible = false; } else { c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".Visible = true; c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".ImageUrl = Utils.AddTilde(GetUrlWithQSHash(dr[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString()));}} catch {c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".Visible = false;}" + Environment.NewLine);
                                            }
                                        }
                                        else
                                        {
                                            sb.Append("				c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".Text = " + Robot.DataTypeConvert(string.Empty, drvs["DisplayName"].ToString(), drvs["DisplayMode"].ToString(), drvs["NumericData"].ToString(), drv["ColumnScale"].ToString(), true) + "dr[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString()" + Robot.DataTypeConvert(string.Empty, drvs["DisplayName"].ToString(), drvs["DisplayMode"].ToString(), drvs["NumericData"].ToString(), string.Empty, false) + ";" + Environment.NewLine);
                                        }
									}
								}
							}
							else if (drv["DisplayName"].ToString() != "CheckBox")
							{
								sb.Append("			if (c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text != string.Empty)" + Environment.NewLine);
								sb.Append("			{" + Environment.NewLine);
							}
							dvs.RowFilter = "MasterTable = 'Y'";
							foreach (DataRowView drvs in dvs)
							{
                                if (drv["ColumnId"].ToString() == drvs["DdlFtrColumnId"].ToString() && !string.IsNullOrEmpty(drvs["DdlFtrColumnId"].ToString()) && drvs["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0)
                                {
									if (",ComboBox,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0)
									{
                                        sb.Append("				if (c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".Mode!=\"A\") c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".ClearSearch();");
                                        sb.Append("				else Set" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "(c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".SelectedValue,c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedValue");
                                        if (("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 || ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drvs["MasterTable"].ToString() != "Y")) && drvs["DisplayName"].ToString() == "ComboBox")
                                        {
                                            sb.Append(", c" + dw["ProgramName"].ToString() + "Grid.EditItem");
                                        }
                                    }
									else
									{
										sb.Append("				Set" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "(c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".SelectedValue,((");
										if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("TextBox"); }
										else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
										else { sb.Append(drv["DisplayName"].ToString()); }
										sb.Append(")sender).");
										if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} else {sb.Append("Text");}
									}
                                    sb.Append(");");
                                    if (drvs["DisplayName"].ToString() != "ComboBox" && drvs["ColPostBack"].ToString() == "Y") { sb.Append(" c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "_SelectedIndexChanged(sender, e);"); }
									sb.Append(Environment.NewLine);
								}
							}
                            if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                            {
								sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Script();" + Environment.NewLine);
							}
                            if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                            {
                                sb.Append("			if (pwd != null) {ScriptManager.GetCurrent(Parent.Page).SetFocus(pwd.ClientID);} else {ScriptManager.GetCurrent(Parent.Page).SetFocus(SenderFocusId(sender));}" + Environment.NewLine);
                                //							if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox)sender).FocusID);}" + Environment.NewLine); } else { sb.Append(drv["DisplayName"].ToString() + ")sender).ClientID);}" + Environment.NewLine); }
                            }
                            if (drv["DisplayName"].ToString() != "CheckBox") { sb.Append("			}" + Environment.NewLine); }
						}
						sb.Append("		}" + Environment.NewLine);
					}
					if (drv["PwdOvride"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
						sb.Append(Environment.NewLine);
						sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd_TextChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						sb.Append("		{" + Environment.NewLine);
						sb.Append("			bool bOk = true;" + Environment.NewLine);
						sb.Append("			DataView dv = ((DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "]).DefaultView;" + Environment.NewLine);
						sb.Append("			DataRowView dr = dv[c" + drv["ColumnName"].ToString() + drv["TableId"].ToString());
						if (",ComboBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0) {sb.Append(".DataSetIndex];" + Environment.NewLine);} else {sb.Append(".SelectedIndex];" + Environment.NewLine);}
						sb.Append("			bool bValid2 = false;" + Environment.NewLine);
						sb.Append("			try" + Environment.NewLine);
						sb.Append("			{" + Environment.NewLine);
                        sb.Append("				bValid2 = !(new AdminSystem()).IsValidOvride(new Credential(dr[\"OvrideId\"].ToString(),((TextBox)sender).Text),0,LcSysConnString,LcAppPw);" + Environment.NewLine);
						sb.Append("			}" + Environment.NewLine);
                        sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
						sb.Append("			if (bValid2)" + Environment.NewLine);
						sb.Append("			{" + Environment.NewLine);
						sb.Append("				if (dr[\"PromptModal\"].ToString() == \"N\") {Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ",string.Empty");
						if (drv["DdlFtrColumnId"].ToString() != string.Empty)
						{
							dvs.RowFilter = string.Empty;
							foreach (DataRowView drvs in dvs)
							{
								if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
								{
									if (drvs["MasterTable"].ToString() == "Y")
									{
										sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
										if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} else {sb.Append("Text");}
									}
									else
									{
										sb.Append(",((" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\")).");
										if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} else {sb.Append("Text");}
									}
								}
							}
						}
                        if (("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 || ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")) && drv["DisplayName"].ToString() == "ComboBox")
                        {
                            sb.Append(", c" + dw["ProgramName"].ToString() + "Grid.EditItem");
                        }
                        sb.Append(");} else {bOk = false;}" + Environment.NewLine);
						sb.Append("			}" + Environment.NewLine);
						sb.Append("			if (bOk)" + Environment.NewLine);
						sb.Append("			{" + Environment.NewLine);
						sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Visible = true; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd.Visible = false; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwl.Visible = false;" + Environment.NewLine);
						//if (clientFrwork == "1")
						//{
						//    sb.Append("				Session[\"CtrlToFocus\"] = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".");
						//    if (",ComboBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0) {sb.Append("FocusID;" + Environment.NewLine);} else {sb.Append("ClientID;" + Environment.NewLine);}
						//    sb.Append("			}" + Environment.NewLine);
						//    sb.Append("			else {Session[\"CtrlToFocus\"] = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd.ClientID; c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwl.Visible = true;}" + Environment.NewLine);
						//}
						//else
						//{
						sb.Append("				ScriptManager.GetCurrent(Parent.Page).SetFocus(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".");
						if (",ComboBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0) {sb.Append("FocusID);" + Environment.NewLine);} else {sb.Append("ClientID);" + Environment.NewLine);}
						sb.Append("			}" + Environment.NewLine);
						sb.Append("			else {ScriptManager.GetCurrent(Parent.Page).SetFocus(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd.ClientID); c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwl.Visible = true;}" + Environment.NewLine);
						//}
						sb.Append("		}" + Environment.NewLine);
					}
				}
			}
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dv.RowFilter = "MasterTable <> 'Y'";} else {dv.RowFilter = string.Empty;}
				foreach (DataRowView drv in dv)
				{
					if ((drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y" || drv["ColumnLink"].ToString() != string.Empty) && drv["ColumnIdentity"].ToString() != "Y" && ",CheckBox,Calendar,TextBox,ComboBox,DropDownList,ListBox,RadioButtonList,Button,ImageButton,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
						sb.Append(Environment.NewLine);
						if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							if (drv["DisplayName"].ToString() == "ComboBox")
							{
								sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged(object sender, System.EventArgs e)" + Environment.NewLine);
								sb.Append("		{" + Environment.NewLine);
								sb.Append("			ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)sender).FocusID);" + Environment.NewLine);
								sb.Append("		}" + Environment.NewLine);
								sb.Append(Environment.NewLine);
								sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_DDFindClick(object sender, System.EventArgs e)" + Environment.NewLine);
								sb.Append("		{" + Environment.NewLine);
								sb.Append("			ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)sender).FocusID);" + Environment.NewLine);
								sb.Append("		}" + Environment.NewLine);
								sb.Append(Environment.NewLine);
							}
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectedIndexChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						else if (",CheckBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_CheckedChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						else if (",Calendar,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectionChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						else if (",Button,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						else if (",ImageButton,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click(object sender, System.Web.UI.ImageClickEventArgs e)" + Environment.NewLine);
						}
						else
						{
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						}
						sb.Append("		{" + Environment.NewLine);
						bWebRule = false;
						foreach (DataRowView drvr in dvWRule)
						{
							if (drvr["EventCode"].ToString() == "SELCHG" && drv["ScreenObjId"].ToString() == drvr["ScreenObjId"].ToString())
							{
								bWebRule = true;
								sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
								sb.Append(WrapConditionalWebRule("   ", drvr));
							}
						}
                        if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** On Change/ On Click Web Rule starts here *** //" + Environment.NewLine); }
                        sb.Append("			EnableValidators(true);  // Do not remove; Need to reenable after postback, especially in the grid." + Environment.NewLine);
                        if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        {
                            sb.Append("			TextBox pwd = null;" + Environment.NewLine);
                        }
                        if (",Button,ImageButton,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0)
						{
                            sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex > -1 && c" + dw["ProgramName"].ToString() + "Grid.Items.Count > c" + dw["ProgramName"].ToString() + "Grid.EditIndex)" + Environment.NewLine);
                            sb.Append("			{" + Environment.NewLine);
                            if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
							{
								if (",DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
								{
                                    sb.Append("				if (Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "] != null)" + Environment.NewLine);
                                    sb.Append("				{" + Environment.NewLine);
                                    sb.Append("					DataView dv1 = ((DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "]).DefaultView; dv1.RowFilter = string.Empty;" + Environment.NewLine);
                                    sb.Append("				}" + Environment.NewLine);
                                }
								if (drv["PwdOvride"].ToString() == "Y")
								{
                                    sb.Append("				if (Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "] != null)" + Environment.NewLine);
                                    sb.Append("				{" + Environment.NewLine);
                                    sb.Append("					DataView dv2 = ((DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "]).DefaultView;" + Environment.NewLine);
                                    sb.Append("					if (dv2.Count > 0)	// In case of Invalid." + Environment.NewLine);
                                    sb.Append("					{" + Environment.NewLine);
                                    sb.Append("						DataRowView dr = dv2[((");
									if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox)sender).SelectedIndex];" + Environment.NewLine); } else { sb.Append("DropDownList)sender).SelectedIndex];" + Environment.NewLine); }
                                    sb.Append("						bool bValid3 = false;" + Environment.NewLine);
                                    sb.Append("						try" + Environment.NewLine);
                                    sb.Append("						{" + Environment.NewLine);
                                    sb.Append("							if ((dv2.Table.Columns.Contains(\"OvrideId\") && dr[\"OvrideId\"].ToString() != string.Empty) && (dr[\"PromptAlways\"].ToString() == \"Y\" || !(new AdminSystem()).IsValidOvride(new Credential(dr[\"OvrideId\"].ToString(),string.Empty),base.LUser.UsrId,LcSysConnString,LcAppPw))) {bValid3 = true;}" + Environment.NewLine);
                                    sb.Append("						}" + Environment.NewLine);
                                    sb.Append("						catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                                    sb.Append("						if (bValid3)" + Environment.NewLine);
                                    sb.Append("						{" + Environment.NewLine);
                                    if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("							RoboCoder.WebControls.ComboBox ddl = (RoboCoder.WebControls.ComboBox"); } else { sb.Append("						" + drv["DisplayName"].ToString() + " ddl = (" + drv["DisplayName"].ToString()); }
									sb.Append(")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\");" + Environment.NewLine);
                                    sb.Append("							pwd = (TextBox)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd\");" + Environment.NewLine);
                                    sb.Append("							ddl.Visible = false; pwd.Visible = true;" + Environment.NewLine);
                                    sb.Append("							ScriptManager.GetCurrent(Parent.Page).SetFocus(pwd.ClientID);" + Environment.NewLine);
                                    sb.Append("						}" + Environment.NewLine);
                                    sb.Append("					}" + Environment.NewLine);
									sb.Append("				}" + Environment.NewLine);
								}
								sb.Append("				DataView dv" + dw["ProgramName"].ToString() + "Grid = ((DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid]).DefaultView;" + Environment.NewLine);
								ii = 0;
								if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dvs.RowFilter = "MasterTable <> 'Y'";} else {dvs.RowFilter = string.Empty;}
                                sb.Append("				if (Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "] != null)" + Environment.NewLine);
                                sb.Append("				{" + Environment.NewLine);
                                sb.Append("					DataView dv3 = ((DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "]).DefaultView;" + Environment.NewLine);
                                foreach (DataRowView drvs in dvs)
								{
                                    if (drv["ColumnId"].ToString() == drvs["DdlRefColumnId"].ToString() && !string.IsNullOrEmpty(drvs["DdlRefColumnId"].ToString()))
                                    {
										sb.Append("				" + drvs["DisplayName"].ToString() + " c" + ii.ToString() + " = (" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\");" + Environment.NewLine);
										sb.Append("				if (c" + ii.ToString() + " != null)" + Environment.NewLine);
										sb.Append("				{" + Environment.NewLine);
										sb.Append("					foreach (DataRowView drv in dv3)" + Environment.NewLine);
										sb.Append("					{" + Environment.NewLine);
										sb.Append("						if (drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() == ((");
										if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("TextBox"); }
										else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
										else { sb.Append(drv["DisplayName"].ToString()); }
										sb.Append(")sender).SelectedValue)" + Environment.NewLine);
										sb.Append("						{" + Environment.NewLine);
										if (",CheckBox,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0)
										{
											sb.Append("							c" + ii.ToString() + ".Checked = base.GetBool(drv[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString());" + Environment.NewLine);
											sb.Append("							dv" + dw["ProgramName"].ToString() + "Grid[c" + dw["ProgramName"].ToString() + "Grid.EditItem.DataSetIndex][\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"] = base.SetBool(c" + ii.ToString() + ".Checked);" + Environment.NewLine);
										}
										else if (",ImageButton,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0)
										{
                                            if (drvs["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                                            {
                                                sb.Append("						    try { if (drv[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].Equals(System.DBNull.Value)) { c" + ii.ToString() + ".ImageUrl = ");
                                                if (drvs["DefaultValue"].ToString() != string.Empty)
                                                {
                                                    sb.Append("\"" + Utils.AddTilde(drvs["DefaultValue"].ToString()) + "\"; }");
                                                }
                                                else
                                                {
                                                    sb.Append("\"~/images/DefaultImg.png\"; }");
                                                }
                                                sb.Append(" else { c" + ii.ToString() + ".ImageUrl = RO.Common3.Utils.BlobPlaceHolder(drv[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"] as byte[], true); }} catch { c" + ii.ToString() + ".ImageUrl = string.Empty; }" + Environment.NewLine);
                                            }
                                            else
                                            {
                                                sb.Append("							try {if (drv[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString() == string.Empty) { c" + ii.ToString() + ".Visible = false; } else { c" + ii.ToString() + ".Visible = true; c" + ii.ToString() + ".ImageUrl = Utils.AddTilde(GetUrlWithQSHash(drv[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString()));}} catch {c" + ii.ToString() + ".Visible = false;}" + Environment.NewLine);
                                                sb.Append("							dv" + dw["ProgramName"].ToString() + "Grid[c" + dw["ProgramName"].ToString() + "Grid.EditItem.DataItemIndex][\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"] = c" + ii.ToString() + ".ImageUrl;" + Environment.NewLine);
                                            }
										}
										else
										{
                                            sb.Append("							c" + ii.ToString() + ".Text = " + Robot.DataTypeConvert(string.Empty, drvs["DisplayName"].ToString(), drvs["DisplayMode"].ToString(), drvs["NumericData"].ToString(), drv["ColumnScale"].ToString(), true) + "drv[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString()" + Robot.DataTypeConvert(string.Empty, drvs["DisplayName"].ToString(), drvs["DisplayMode"].ToString(), drvs["NumericData"].ToString(), string.Empty, false) + ";" + Environment.NewLine);
                                            sb.Append("							dv" + dw["ProgramName"].ToString() + "Grid[c" + dw["ProgramName"].ToString() + "Grid.EditItem.DataItemIndex][\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"] = drv[\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"];" + Environment.NewLine);
										}
										sb.Append("							break;" + Environment.NewLine);
										sb.Append("						}" + Environment.NewLine);
										sb.Append("					}" + Environment.NewLine);
										sb.Append("				}" + Environment.NewLine);
									}
									ii = ii + 1;
								}
                                sb.Append("				}" + Environment.NewLine);
                                sb.Append("				Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dv" + dw["ProgramName"].ToString() + "Grid.Table;" + Environment.NewLine);
							}
                            // Need to find out if TextBox should be included in the following:
							if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dvs.RowFilter = "MasterTable <> 'Y'";} else {dvs.RowFilter = string.Empty;}
							foreach (DataRowView drvs in dvs)
							{
                                if (!string.IsNullOrEmpty(drvs["DdlFtrColumnId"].ToString()) && drv["ColumnId"].ToString() == drvs["DdlFtrColumnId"].ToString() && drvs["ColumnIdentity"].ToString() != "Y" && ",TextBox,ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0)
								{
									sb.Append("				Set" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "((");
									if (drvs["DisplayName"].ToString() == "ComboBox") { sb.Append("RoboCoder.WebControls.ComboBox"); } else sb.Append(drvs["DisplayName"].ToString());
									sb.Append(")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\"),dv" + dw["ProgramName"].ToString() + "Grid[c" + dw["ProgramName"].ToString() + "Grid.EditItem.DataItemIndex][\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString(),((");
									if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("TextBox"); }
									else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
									else { sb.Append(drv["DisplayName"].ToString()); }
                                    sb.Append(")sender).");
									if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} else {sb.Append("Text");}
                                    if (("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 || ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drvs["MasterTable"].ToString() != "Y")) && drvs["DisplayName"].ToString() == "ComboBox")
                                    {
                                        sb.Append(", c" + dw["ProgramName"].ToString() + "Grid.EditItem");
                                    }
                                    sb.Append(");");
									if (drvs["DisplayName"].ToString() != "ComboBox" && drvs["ColPostBack"].ToString() == "Y") {sb.Append(" c" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "_SelectedIndexChanged(sender, e);");}
									sb.Append(Environment.NewLine);
								}
							}
                            if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                            {
								sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Script();" + Environment.NewLine);
							}
							sb.Append("			}" + Environment.NewLine);
						}
                        if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
						{
                            sb.Append("			if (pwd != null) {ScriptManager.GetCurrent(Parent.Page).SetFocus(pwd.ClientID);} else {ScriptManager.GetCurrent(Parent.Page).SetFocus(SenderFocusId(sender));}" + Environment.NewLine);
						}
                        sb.Append("		}" + Environment.NewLine);
                    }
					if (drv["PwdOvride"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
						sb.Append(Environment.NewLine);
						sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd_TextChanged(object sender, System.EventArgs e)" + Environment.NewLine);
						sb.Append("		{" + Environment.NewLine);
						sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex > -1 && c" + dw["ProgramName"].ToString() + "Grid.Items.Count > c" + dw["ProgramName"].ToString() + "Grid.EditIndex && Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "] != null)" + Environment.NewLine);
						sb.Append("			{" + Environment.NewLine);
						sb.Append("				bool bOk = true;" + Environment.NewLine);
						sb.Append("				DataTable dt = (DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "];" + Environment.NewLine);
						sb.Append("				DataView dv = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
						if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("				RoboCoder.WebControls.ComboBox ddl = (RoboCoder.WebControls.ComboBox"); } else { sb.Append("				" + drv["DisplayName"].ToString() + " ddl = (" + drv["DisplayName"].ToString()); }
						sb.Append(")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\");" + Environment.NewLine);
						if (",ComboBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0) {sb.Append("				DataRowView dr = dv[ddl.DataSetIndex];" + Environment.NewLine);} else {sb.Append("				DataRowView dr = dv[ddl.SelectedIndex];" + Environment.NewLine);}
						sb.Append("				bool bValid4 = false;" + Environment.NewLine);
						sb.Append("				try" + Environment.NewLine);
						sb.Append("				{" + Environment.NewLine);
                        sb.Append("					if (!(new AdminSystem()).IsValidOvride(new Credential(dr[\"OvrideId\"].ToString(),((TextBox)sender).Text),0,LcSysConnString,LcAppPw)) {bValid4 = true;}" + Environment.NewLine);
						sb.Append("				}" + Environment.NewLine);
                        sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
						sb.Append("				if (bValid4)" + Environment.NewLine);
						sb.Append("				{" + Environment.NewLine);
						sb.Append("					if (dr[\"PromptModal\"].ToString() == \"N\") {Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(ddl,string.Empty");
						if (drv["DdlFtrColumnId"].ToString() != string.Empty)
						{
							dvs.RowFilter = string.Empty;
							foreach (DataRowView drvs in dvs)
							{
								if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
								{
									if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drvs["MasterTable"].ToString() == "Y")
									{
										sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
										if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} else {sb.Append("Text");}
									}
									else
									{
										sb.Append(",((" + (drvs["DisplayName"].ToString() == "ComboBox" ? "RoboCoder.WebControls.ComboBox" : drvs["DisplayName"].ToString()) + ")c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + "\")).");
										if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drvs["DisplayName"].ToString()+",") >= 0) {sb.Append("SelectedValue");} else {sb.Append("Text");}
									}
								}
							}
						}
                        if (("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 || ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")) && drv["DisplayName"].ToString() == "ComboBox")
                        {
                            sb.Append(", c" + dw["ProgramName"].ToString() + "Grid.EditItem");
                        }
                        sb.Append(");} else {bOk = false;}" + Environment.NewLine);
						sb.Append("				}" + Environment.NewLine);
						sb.Append("				Label pwl = (Label)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwl\");" + Environment.NewLine);
						sb.Append("				if (bOk)" + Environment.NewLine);
						sb.Append("				{" + Environment.NewLine);
						sb.Append("					ddl.Visible = true; ((TextBox)sender).Visible = false; pwl.Visible = false;" + Environment.NewLine);
						if (clientFrwork == "1")
						{
							sb.Append("					Session[\"CtrlToFocus\"] = ddl.");
							if (",ComboBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0) {sb.Append("FocusID;" + Environment.NewLine);} else {sb.Append("ClientID;" + Environment.NewLine);}
							sb.Append("				}" + Environment.NewLine);
							sb.Append("				else {Session[\"CtrlToFocus\"] = ((TextBox)sender).ClientID; pwl.Visible = true;}" + Environment.NewLine);
						}
						else
						{
							sb.Append("					ScriptManager.GetCurrent(Parent.Page).SetFocus(ddl.");
							if (",ComboBox,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0) {sb.Append("FocusID);" + Environment.NewLine);} else {sb.Append("ClientID);" + Environment.NewLine);}
							sb.Append("				}" + Environment.NewLine);
							sb.Append("				else {ScriptManager.GetCurrent(Parent.Page).SetFocus(((TextBox)sender).ClientID); pwl.Visible = true;}" + Environment.NewLine);
						}
						sb.Append("			}" + Environment.NewLine);
						sb.Append("		}" + Environment.NewLine);
					}
				}
			}
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append(Environment.NewLine);
				sb.Append("		public void cFindButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Find")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Find")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
					sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
					sb.Append("			DataView dv = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
					sb.Append("			if (dv != null)" + Environment.NewLine);
					sb.Append("			{" + Environment.NewLine);
					if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
					{
						sb.Append("				WebControl cc = sender as WebControl;" + Environment.NewLine);
                        sb.Append("				if ((cc != null && cc.ID.Equals(\"c" + dw["ProgramName"].ToString() + screenId.ToString() + "List\")) || c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || UpdateGridRow(c" + dw["ProgramName"].ToString() + "Grid, new CommandEventArgs(\"Save\", \"\")))" + Environment.NewLine);
					}
					else
					{
                        sb.Append("				if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || UpdateGridRow(c" + dw["ProgramName"].ToString() + "Grid, new CommandEventArgs(\"Save\", \"\")))" + Environment.NewLine);
					}
					sb.Append("				{" + Environment.NewLine);
                    //sb.Append("					dv.RowFilter = \"_CurRow = 'Y'\";" + Environment.NewLine);
                    //sb.Append("					foreach (DataRowView drv in dv) { drv[\"_CurRow\"] = \"N\"; }" + Environment.NewLine);
					sb.Append("					string rf = string.Empty;" + Environment.NewLine);
                    sb.Append("					if (cFind.Text != string.Empty) { rf = \"(\" + base.GetExpression(cFind.Text.Trim(), GetAuthCol(), " + iOffset.ToString() + ", cFindFilter.SelectedValue) + \")\"; }" + Environment.NewLine);
					if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = "MasterTable = 'Y'"; }
                    sb.Append("					if (rf != string.Empty) { rf = \"((\" + rf + \" or _NewRow = 'Y' ))\"; }" + Environment.NewLine);
					sb.Append("					dv.RowFilter = rf;" + Environment.NewLine);
					sb.Append("					ViewState[\"_RowFilter\"] = rf;" + Environment.NewLine);
                    //if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                    //{
                    //    sb.Append("					if (!(GetAuthRow().Rows[0][\"AllowUpd\"].ToString() == \"N\" && GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"N\") && !(Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))");
                    //}
                    //else
                    //{
                    //    sb.Append("					if (GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"Y\")");
                    //}
                    //sb.Append(" {c" + dw["ProgramName"].ToString() + "Grid_AddNew(dt);}" + Environment.NewLine);
                    sb.Append("					GotoPage(0); c" + dw["ProgramName"].ToString() + "Grid_DataBind(dv);" + Environment.NewLine);
                    sb.Append("					if (GetCurrPageIndex() != (int)Session[KEY_currPageIndex] && (int)Session[KEY_currPageIndex] < GetTotalPages()) { GotoPage((int)Session[KEY_currPageIndex]); c" + dw["ProgramName"].ToString() + "Grid_DataBind(dv);}" + Environment.NewLine);
					sb.Append("					try {ScriptManager.GetCurrent(Parent.Page).SetFocus(((TextBox)sender).ClientID);} catch {}" + Environment.NewLine);
					sb.Append("				}" + Environment.NewLine);
					sb.Append("			}" + Environment.NewLine);
                    sb.Append("			grdCount.InnerText = \"(\" + RO.Common3.Utils.fmNumeric(\"0\",dv.Count.ToString(),base.LUser.Culture) + \" found)\";" + Environment.NewLine);
                    bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Find")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cFirstButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "First")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "First")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
					sb.Append("			GotoPage(0);" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "First")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cLastButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Last")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Last")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			GotoPage(GetTotalPages() - 1);" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Last")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cNextButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Next")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Next")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			GotoPage(GetCurrPageIndex() + 1);" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Next")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cPrevButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Prev")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Prev")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			GotoPage(GetCurrPageIndex() - 1);" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Prev")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
                sb.Append("		public void cInsRowButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
                    if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "InsRow")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
                else
                {
                    bWebRule = false;
                    foreach (DataRowView drvr in dvWRule)
                    {
                        if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "InsRow")
                        {
                            bWebRule = true;
                            sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                            sb.Append(WrapConditionalWebRule("   ", drvr));
                        }
                    }
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                    sb.Append("			if (dt != null && (ValidPage()) && UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\")))" + Environment.NewLine);
                    sb.Append("			{" + Environment.NewLine);
                    sb.Append("				DataRow dr = dt.NewRow();" + Environment.NewLine);
                    sb.Append("				int? sortorder = null;" + Environment.NewLine);
                    if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = "MasterTable = 'Y'"; }
                    foreach (DataRowView drv in dv)
                    {
                        if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
                        {
                            sb.Append("				dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = ");
                            if (",LongDate,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                            {
                                try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToLongDateString();"); }
                                catch { sb.Append(drv["DefaultValue"].ToString() + ".ToLongDateString();"); }
                            }
                            else if (",LongDateTime,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                            {
                                try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"f\");"); }
                                catch { sb.Append(drv["DefaultValue"].ToString() + ".ToString(\"f\");"); }
                            }
                            else if (",LongDateTimeUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                            {
                                try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"f\");"); }
                                catch { sb.Append(drv["DefaultValue"].ToString() + ".ToUniversalTime().ToString(\"f\");"); }
                            }
                            else if (",DateTimeUTC,ShortDateTimeUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                            {
                                try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"g\");"); }
                                catch { sb.Append(drv["DefaultValue"].ToString() + ".ToUniversalTime().ToString(\"g\");"); }
                            }
                            else if (",ShortDateTime,DateTime,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                            {
                                try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"g\");"); }
                                catch { sb.Append(drv["DefaultValue"].ToString() + ".ToString(\"g\");"); }
                            }
                            else if (",ShortDate,Date,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                            {
                                try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToShortDateString();"); }
                                catch { sb.Append(drv["DefaultValue"].ToString() + ".ToShortDateString();"); }
                            }
                            else if (",DateUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                            {
                                try { DateTime.Parse(drv["DefaultValue"].ToString()); sb.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToShortDateString();"); }
                                catch { sb.Append(drv["DefaultValue"].ToString() + ".ToUniversalTime().ToShortDateString();"); }
                            }
                            else
                            {
                                sb.Append(Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + ";");
                            }
                            sb.Append(Environment.NewLine);
                        }
                    }
                    sb.Append("				if (dt.Columns.Contains(\"_SortOrder\"))" + Environment.NewLine);
                    sb.Append("				{" + Environment.NewLine);
                    sb.Append("				    try" + Environment.NewLine);
                    sb.Append("				    {" + Environment.NewLine);
                    //sb.Append("				        if (string.IsNullOrEmpty(dt.DefaultView[0][\"_SortOrder\"].ToString())) dt.DefaultView[0][\"_SortOrder\"] = 0;" + Environment.NewLine);
                    //sb.Append("				        sortorder = ((int)dt.DefaultView[0][\"_SortOrder\"]) - 1;" + Environment.NewLine);
                    sb.Append("				        sortorder = 1;" + Environment.NewLine);
                    sb.Append("				    } catch {};" + Environment.NewLine);
                    sb.Append("				}" + Environment.NewLine);
                    sb.Append("				dt.Rows.InsertAt(dr, 0);" + Environment.NewLine);
                    sb.Append("				dt.Rows[0][\"_NewRow\"] = \"Y\";" + Environment.NewLine);
                    sb.Append("				if (sortorder.HasValue) dr[\"_SortOrder\"] = sortorder;" + Environment.NewLine);
                    sb.Append("				Session[KEY_lastAddedRow] = 0; Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dt; Session[KEY_currPageIndex] = 0; GotoPage(0);" + Environment.NewLine);
                    sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_DataBind(dt.DefaultView);" + Environment.NewLine);
                    sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_OnItemEditing(c" + dw["ProgramName"].ToString() + "Grid, new ListViewEditEventArgs(0));" + Environment.NewLine);
                    bWebRule = false;
                    foreach (DataRowView drvr in dvWRule)
                    {
                        if (drvr["EventCode"].ToString() == "DEFVAG")
                        {
                            bWebRule = true;
                            sb.Append("				//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                            sb.Append(WrapConditionalWebRule("   ", drvr));
                        }
                    }
                    if (bWebRule) { sb.Append("				// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("				// *** Default Value (Grid) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			}" + Environment.NewLine);
                    bWebRule = false;
                    foreach (DataRowView drvr in dvWRule)
                    {
                        if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "InsRow")
                        {
                            bWebRule = true;
                            sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                            sb.Append(WrapConditionalWebRule("   ", drvr));
                        }
                    }
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
                }
                sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cPgSizeButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || (dt != null && UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"))))" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				try {if (int.Parse(cPgSize.Text) < 1 || int.Parse(cPgSize.Text) > 200) {cPgSize.Text = \"" + dw["GridRows"].ToString() + "\";}} catch {cPgSize.Text = \"" + dw["GridRows"].ToString() + "\";}" + Environment.NewLine);
                sb.Append("				c" + dw["ProgramName"].ToString() + "GridDataPager.PageSize = int.Parse(cPgSize.Text); GotoPage(0);" + Environment.NewLine);
				sb.Append("				if (dt.Rows.Count <= 0 || (");
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
                    sb.Append("!((GetAuthRow().Rows[0][\"AllowUpd\"].ToString() == \"N\" || GetAuthRow().Rows[0][\"ViewOnly\"].ToString() == \"G\") && GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"N\") && !(Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\")");
				}
				else
				{
					sb.Append("GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"Y\"");
				}
				sb.Append(" && dt.Rows.Count == 1)) {c" + dw["ProgramName"].ToString() + "Grid_DataBind(dt.DefaultView);} else {cFindButton_Click(sender, e);}" + Environment.NewLine);
				sb.Append("				try" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
                //sb.Append("					if (Config.Architect == \"W\")" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                //sb.Append("						AdminFacade().UpdLastPageInfo(" + screenId.ToString() + ", base.LUser.UsrId, cPgSize.Text, LcSysConnString, LcAppPw);" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
                //sb.Append("					else" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                sb.Append("					(new AdminSystem()).UpdLastPageInfo(" + screenId.ToString() + ", base.LUser.UsrId, cPgSize.Text, LcSysConnString, LcAppPw);" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
                sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); }" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
                sb.Append("		public void cGoto_TextChanged(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Goto")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Goto")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			try {GotoPage(Convert.ToInt32(cGoto.Text) - 1);} catch {} finally {cGoto.Text = (GetCurrPageIndex() + 1).ToString();}" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Goto")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cHideImpButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "HideImp")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "HideImp")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
					sb.Append("			cImport.Visible = false; cHideImpButton.Visible = false; cShowImpButton.Visible = (bool)Session[KEY_bShImpVisible];" + Environment.NewLine);
					sb.Append("			cNaviPanel.Visible = true; cImportPwdPanel.Visible = false;" + Environment.NewLine);
					sb.Append("			if ((cShowImpButton.Attributes[\"OnClick\"] == null || cShowImpButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) && cShowImpButton.Visible) {cShowImpButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "HideImp")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cShowImpButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ShowImp")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ShowImp")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
					sb.Append("			cImport.Visible = true; cShowImpButton.Visible = false; cHideImpButton.Visible = (bool)Session[KEY_bHiImpVisible];" + Environment.NewLine);
                    sb.Append("			cNaviPanel.Visible = false; cImportPwdPanel.Visible = false;" + Environment.NewLine);
					sb.Append("			if ((cImportButton.Attributes[\"OnClick\"] == null || cImportButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) && cImportButton.Visible) {cImportButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
					sb.Append("			if ((cHideImpButton.Attributes[\"OnClick\"] == null || cHideImpButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) && cHideImpButton.Visible) {cHideImpButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
					sb.Append("			if (cSchemaImage.Visible)" + Environment.NewLine);
					sb.Append("			{" + Environment.NewLine);
					sb.Append("				try" + Environment.NewLine);
					sb.Append("				{" + Environment.NewLine);
                    sb.Append("					Session[\"ImportSchema\"] = (new AdminSystem()).GetSchemaScrImp(" + screenId.ToString() + ",base.LUser.CultureId,LcSysConnString,LcAppPw);" + Environment.NewLine);
					sb.Append("				}" + Environment.NewLine);
                    sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                    sb.Append("				if (cSchemaImage.Attributes[\"OnClick\"] == null || cSchemaImage.Attributes[\"OnClick\"].IndexOf(\"ImportSchema.aspx\") < 0) {cSchemaImage.Attributes[\"OnClick\"] += \"SearchLink('ImportSchema.aspx?scm=S&key=" + screenId.ToString() + "&csy=" + CSrc.SrcSystemId.ToString() + "','','',''); return false;\";}" + Environment.NewLine);
                    sb.Append("			}" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "ShowImp")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		private void ScrImportDdl(DataView dvd, DataRowView drv, bool bComboBox, string PKey, string CKey, string CNam, int MaxLen, string MatchCd, bool bAllowNulls)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                sb.Append("			if (dvd != null)" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                {
                    //Filter on primary key of calling table:
                    sb.Append("				if (dvd.Table.Columns.Contains(PKey))" + Environment.NewLine);
                    sb.Append("				{" + Environment.NewLine);
                    sb.Append("					if (string.IsNullOrEmpty(c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue))" + Environment.NewLine);
                    sb.Append("					{" + Environment.NewLine);
                    sb.Append("						dvd.RowFilter = \"(\" + PKey + \" is null)\";" + Environment.NewLine);
                    sb.Append("					}" + Environment.NewLine);
                    sb.Append("					else" + Environment.NewLine);
                    sb.Append("					{" + Environment.NewLine);
                    sb.Append("						dvd.RowFilter = \"(\" + PKey + \" is null OR \" + PKey + \" = ");
                    if (",Char,VarChar,NChar,NVarChar,SmallDateTime,DateTime,".IndexOf("," + pMKeySqlName + ",") >= 0) { sb.Append("'"); }
                    sb.Append("\" + c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue");
                    if (",Char,VarChar,NChar,NVarChar,SmallDateTime,DateTime,".IndexOf("," + pMKeySqlName + ",") >= 0) { sb.Append(" + \"'\""); }
                    sb.Append(" + \")\";" + Environment.NewLine);
                    sb.Append("					}" + Environment.NewLine);
                    sb.Append("				}" + Environment.NewLine);
                }
                // Test for same description but different keys on the server side (assuming this dropddown/combobox is sorted by description):
				sb.Append("				bool bFound = false; bool bUnique = true;" + Environment.NewLine);
                sb.Append("				if (!string.IsNullOrEmpty(drv[CKey].ToString().Trim()))   // Always do this first." + Environment.NewLine);
                sb.Append("				{" + Environment.NewLine);
                sb.Append("					foreach (DataRowView drvd in dvd)" + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
                sb.Append("						if (drvd[0].ToString().Trim() == drv[CKey].ToString().Trim()) {drv[CNam] = drvd[1].ToString(); bFound = true; break;}" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
                sb.Append("				if (!string.IsNullOrEmpty(drv[CNam].ToString().Trim()))" + Environment.NewLine);
                sb.Append("				{" + Environment.NewLine);
                sb.Append("					if (drv[CNam].ToString().Length > MaxLen) { drv[CNam] = drv[CNam].ToString().Substring(0,MaxLen); }" + Environment.NewLine);
                sb.Append("					string cnam = drv[CNam].ToString(); object ckey = drv[CKey];	// Saved for reverse later." + Environment.NewLine);
                sb.Append("					if (!bFound && \"2,3,4\".IndexOf(MatchCd) >= 0)  // Exact match." + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
                sb.Append("						foreach (DataRowView drvd in dvd)" + Environment.NewLine);
                sb.Append("						{" + Environment.NewLine);
                sb.Append("							if (drvd[1].ToString().Trim().ToLower() == cnam.Trim().ToLower())" + Environment.NewLine);
                //sb.Append("							if (drvd[1].ToString().Trim().ToLower() == drv[CNam].ToString().Trim().ToLower())" + Environment.NewLine);
                sb.Append("							{" + Environment.NewLine);
                sb.Append("								drv[CKey] = drvd[0].ToString();" + Environment.NewLine);
                sb.Append("								if (bComboBox) {drv[CNam] = drvd[1].ToString();}" + Environment.NewLine);
				sb.Append("								if (!bFound) {bFound = true;}" + Environment.NewLine);
				sb.Append("								else { bUnique = false; drv[CNam] = cnam; drv[CKey] = ckey; break; }" + Environment.NewLine);
				sb.Append("							}" + Environment.NewLine);
				sb.Append("							else if (bFound) break;" + Environment.NewLine);
                sb.Append("						}" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                sb.Append("					if (!bFound && \"3,4\".IndexOf(MatchCd) >= 0)  // StartsWith." + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
                sb.Append("						foreach (DataRowView drvd in dvd)" + Environment.NewLine);
                sb.Append("						{" + Environment.NewLine);
                sb.Append("							if (drvd[1].ToString().Trim().ToLower().StartsWith(cnam.Trim().ToLower()))" + Environment.NewLine);
                //sb.Append("							if (drvd[1].ToString().Trim().ToLower().StartsWith(drv[CNam].ToString().Trim().ToLower()))" + Environment.NewLine);
                sb.Append("							{" + Environment.NewLine);
                sb.Append("								drv[CKey] = drvd[0].ToString();" + Environment.NewLine);
                sb.Append("								if (bComboBox) {drv[CNam] = drvd[1].ToString();}" + Environment.NewLine);
				sb.Append("								if (!bFound) {bFound = true;}" + Environment.NewLine);
				sb.Append("								else { bUnique = false; drv[CNam] = cnam; drv[CKey] = ckey; break; }" + Environment.NewLine);
				sb.Append("							}" + Environment.NewLine);
				sb.Append("							else if (bFound) break;" + Environment.NewLine);
                sb.Append("						}" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                sb.Append("					if (!bFound && \"4\".IndexOf(MatchCd) >= 0)  // Wild search." + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
                sb.Append("						foreach (DataRowView drvd in dvd)" + Environment.NewLine);
                sb.Append("						{" + Environment.NewLine);
                sb.Append("							if (drvd[1].ToString().Trim().ToLower().IndexOf(cnam.Trim().ToLower()) >= 0)" + Environment.NewLine);
                //sb.Append("							if (drvd[1].ToString().Trim().ToLower().IndexOf(drv[CNam].ToString().Trim().ToLower()) >= 0)" + Environment.NewLine);
                sb.Append("							{" + Environment.NewLine);
                sb.Append("								drv[CKey] = drvd[0].ToString();" + Environment.NewLine);
                sb.Append("								if (bComboBox) {drv[CNam] = drvd[1].ToString();}" + Environment.NewLine);
				sb.Append("								if (!bFound) {bFound = true;}" + Environment.NewLine);
				sb.Append("								else { bUnique = false; drv[CNam] = cnam; drv[CKey] = ckey; break; }" + Environment.NewLine);
				sb.Append("							}" + Environment.NewLine);
				sb.Append("							else if (bFound) break;" + Environment.NewLine);
                sb.Append("						}" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                // Do not test "drv[CKey].ToString() == string.Empty" because numeric key could become zero when empty.
                // bAllowNulls is not being used for now.
                sb.Append("					if (!(bFound && bUnique) && MatchCd != \"1\") {drv[CNam] = \"Invalid>\" + drv[CNam].ToString(); bErrNow.Value = \"Y\"; PreMsgPopup(\"Import has invalid data, please check for \\\"Invalid>\\\", rectify and try again.\");}" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
                sb.Append("				if (!bFound && !string.IsNullOrEmpty(drv[CKey].ToString()))" + Environment.NewLine);
                sb.Append("				{" + Environment.NewLine);
                sb.Append("					drv[CNam] = \"Invalid>\" + drv[CKey].ToString(); bErrNow.Value = \"Y\"; PreMsgPopup(\"Import has invalid data, please check for \\\"Invalid>\\\", rectify and try again.\");" + Environment.NewLine);
                sb.Append("				    drv[CKey] = null;" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
				sb.Append("		protected void ScrImport(bool bClear)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			int iRow;" + Environment.NewLine);
				sb.Append("			cNaviPanel.Visible = true; cImportPwdPanel.Visible = false;" + Environment.NewLine);
				sb.Append("			DataTable dti = (DataTable)Session[KEY_scrImport];" + Environment.NewLine);
                sb.Append("			DataTable dt" + dw["ProgramName"].ToString() + "Grid = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                sb.Append("			if (dti != null && dt" + dw["ProgramName"].ToString() + "Grid != null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				if (bClear)" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					dt" + dw["ProgramName"].ToString() + "Grid.Rows.Clear();" + Environment.NewLine);
                //if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                //{
                //    sb.Append("					if (!(GetAuthRow().Rows[0][\"AllowUpd\"].ToString() == \"N\" && GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"N\") && !(Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))");
                //}
                //else
                //{
                //    sb.Append("					if (GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"Y\")");
                //}
                //sb.Append(" {c" + dw["ProgramName"].ToString() + "Grid_AddNew(dt" + dw["ProgramName"].ToString() + "Grid);}" + Environment.NewLine);
                //sb.Append("					Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dt" + dw["ProgramName"].ToString() + "Grid;" + Environment.NewLine);
                //sb.Append("					GotoPage(0);" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("				cFind.Text = string.Empty;" + Environment.NewLine);
				sb.Append("				int iExist = dt" + dw["ProgramName"].ToString() + "Grid.Rows.Count;" + Environment.NewLine);
				//if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				//{
				//    sb.Append("				if (!(GetAuthRow().Rows[0][\"AllowUpd\"].ToString() == \"N\" && GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"N\") && !(Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))");
				//}
				//else
				//{
				//    sb.Append("				if (GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"Y\")");
				//}
				//sb.Append(" {iExist = iExist - 1;}" + Environment.NewLine);
				foreach (DataRowView drv in dv)
				{
					if (drv["PwdOvride"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
                        /* Need the following to create the appropriate s.proc. for detail table */
                        using (GenScreensAccessBase dac = GetGenScreensAccess())
                        {
                            dac.GetScreenObjDdlById(screenId, Int32.Parse(drv["ScreenObjId"].ToString()), "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString(), "N", appDatabase, sysDatabase, CPrj.SrcDesDatabase, pMKey, drv["MultiDesignDb"].ToString(), CSrc);
                        }
						sb.Append("				DataTable dt = null;" + Environment.NewLine);
						sb.Append("				int iLast = (int)Session[KEY_lastImpPwdOvride];" + Environment.NewLine);
						sb.Append("				int ii = 0;" + Environment.NewLine);
						sb.Append("				try" + Environment.NewLine);
						sb.Append("				{" + Environment.NewLine);
						sb.Append("					foreach (DataRowView drv in dti.DefaultView)" + Environment.NewLine);
						sb.Append("					{" + Environment.NewLine);
						sb.Append("						if ((drv.Row.RowState == System.Data.DataRowState.Added || drv.Row.RowState == System.Data.DataRowState.Detached) && ii >= iLast && ii >= iExist)" + Environment.NewLine);
						sb.Append("						{" + Environment.NewLine);
                        //sb.Append("							if (Config.Architect == \"W\")" + Environment.NewLine);
                        //sb.Append("							{" + Environment.NewLine);
                        //sb.Append("								dt = XmlUtils.XmlToDataTable(" + dw["ProgramName"].ToString() + "Facade().GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "(" + screenId.ToString() + ",false,0,drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()" + Robot.GetCnCall(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr)));" + Environment.NewLine);
                        //sb.Append("							}" + Environment.NewLine);
                        //sb.Append("							else" + Environment.NewLine);
                        //sb.Append("							{" + Environment.NewLine);
                        string sAddNew = ",false";
                        if (drv["DisplayName"].ToString() == "ComboBox" || drv["DisplayName"].ToString() == "DropDownList" || (drv["AllowNulls"].ToString() == "Y" && drv["RequiredValid"].ToString() == "N" && drv["DisplayMode"].ToString() != "Document")) { sAddNew = ",true"; }
                        sb.Append("							dt = (new AdminSystem()).GetDdl(" + screenId.ToString() + ",\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\"" + sAddNew + ",false,0,drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr);" + Environment.NewLine);
                        //sb.Append("								dt = (new " + dw["ProgramName"].ToString() + "System()).GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "(" + screenId.ToString() + ",false,0,drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()" + Robot.GetCnCall(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr);" + Environment.NewLine);
                        //sb.Append("							}" + Environment.NewLine);
						string rw;
						if (drv["AllowNulls"].ToString() == "Y" && drv["RequiredValid"].ToString() == "N")
						{
							rw = "1"; sb.Append("							if (dt != null && dt.Rows.Count == 2)" + Environment.NewLine);
						}
						else
						{
							rw = "0"; sb.Append("							if (dt != null && dt.Rows.Count == 1)" + Environment.NewLine);
						}
						sb.Append("							{" + Environment.NewLine);
						sb.Append("								if (dt.Columns.Contains(\"OvrideId\") && dt.Rows[" + rw + "][\"OvrideId\"].ToString() != string.Empty)" + Environment.NewLine);
						sb.Append("								{" + Environment.NewLine);
						sb.Append("									bool bValid5 = false;" + Environment.NewLine);
                        //sb.Append("									if (Config.Architect == \"W\")" + Environment.NewLine);
                        //sb.Append("									{" + Environment.NewLine);
                        //sb.Append("										if ((dt.Rows[" + rw + "][\"PromptAlways\"].ToString() == \"Y\" ||");
                        //sb.Append(" !AdminFacade().IsValidOvride(XmlUtils.ObjectToXml(new RO.Common3.Data.Credential(dt.Rows[" + rw + "][\"OvrideId\"].ToString(),string.Empty)),base.LUser.UsrId,LcSysConnString,LcAppPw)) &&");
                        //sb.Append(" !AdminFacade().IsValidOvride(XmlUtils.ObjectToXml(new RO.Common3.Data.Credential(dt.Rows[" + rw + "][\"OvrideId\"].ToString(),cImportPwd.Text)),0,LcSysConnString,LcAppPw)) {bValid5 = true;}" + Environment.NewLine);
                        //sb.Append("									}" + Environment.NewLine);
                        //sb.Append("									else" + Environment.NewLine);
                        //sb.Append("									{" + Environment.NewLine);
                        sb.Append("									if ((dt.Rows[" + rw + "][\"PromptAlways\"].ToString() == \"Y\" ||");
                        sb.Append(" !(new AdminSystem()).IsValidOvride(new Credential(dt.Rows[" + rw + "][\"OvrideId\"].ToString(),string.Empty),base.LUser.UsrId,LcSysConnString,LcAppPw)) &&");
                        sb.Append(" !(new AdminSystem()).IsValidOvride(new Credential(dt.Rows[" + rw + "][\"OvrideId\"].ToString(),cImportPwd.Text),0,LcSysConnString,LcAppPw)) {bValid5 = true;}" + Environment.NewLine);
                        //sb.Append("									}" + Environment.NewLine);
						sb.Append("									if (bValid5)" + Environment.NewLine);
						sb.Append("									{" + Environment.NewLine);
						sb.Append("										cNaviPanel.Visible = false; cImportPwdPanel.Visible = true; Session[KEY_lastImpPwdOvride] = ii;");
						if (clientFrwork == "1") {sb.Append(" Session[\"CtrlToFocus\"] = cImportPwd.ClientID;" + Environment.NewLine);} else {sb.Append(" ScriptManager.GetCurrent(Parent.Page).SetFocus(cImportPwd.ClientID);" + Environment.NewLine);}
						sb.Append("										if ((cContinueButton.Attributes[\"OnClick\"] == null || cContinueButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) && cContinueButton.Visible) {cContinueButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
						sb.Append("										ii = ii - iExist + 1;" + Environment.NewLine);
                        sb.Append("										bInfoNow.Value = \"Y\"; PreMsgPopup(\"Please enter a password override for '\" + drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"].ToString() + \"' on import row \" + ii.ToString() + \" and select Continue.\");" + Environment.NewLine);
						sb.Append("										return;" + Environment.NewLine);
						sb.Append("									}" + Environment.NewLine);
						sb.Append("									Session[KEY_cntImpPwdOvride] = (int)Session[KEY_cntImpPwdOvride] + 1;" + Environment.NewLine);
						sb.Append("									if (Session[\"CtrlAcctList\"] == null)" + Environment.NewLine);
						sb.Append("									{" + Environment.NewLine);
						sb.Append("										System.Collections.Hashtable ht = new System.Collections.Hashtable();" + Environment.NewLine);
						sb.Append("										ht.Add(drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"].ToString(), 1);" + Environment.NewLine);
						sb.Append("										Session[\"CtrlAcctList\"] = ht;" + Environment.NewLine);
						sb.Append("									}" + Environment.NewLine);
						sb.Append("									else" + Environment.NewLine);
						sb.Append("									{" + Environment.NewLine);
						sb.Append("										System.Collections.Hashtable ht = (System.Collections.Hashtable) Session[\"CtrlAcctList\"];" + Environment.NewLine);
						sb.Append("										if (ht.Contains(drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"].ToString())) {ht[drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"].ToString()] = Int32.Parse(ht[drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"].ToString()].ToString()) + 1;} else {ht.Add(drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"].ToString(), 1);}" + Environment.NewLine);
						sb.Append("										Session[\"CtrlAcctList\"] = ht;" + Environment.NewLine);
						sb.Append("									}" + Environment.NewLine);
						sb.Append("								}" + Environment.NewLine);
						sb.Append("							}" + Environment.NewLine);
						sb.Append("						}" + Environment.NewLine);
						sb.Append("						ii = ii + 1;" + Environment.NewLine);
						sb.Append("					}" + Environment.NewLine);
						sb.Append("				}" + Environment.NewLine);
                        sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
						break;	// Only test one column for password override to avoid infinite loop.
					}
				}
				bool bDdlFound = false;
				foreach (DataRowView drv in dv)
				{
					if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
						if (!bDdlFound)
						{
							bDdlFound = true;
							sb.Append("				// Validate dropdown, combobox, etc." + Environment.NewLine);
							sb.Append("				int jj = 0;" + Environment.NewLine);
                            sb.Append("				foreach (DataRowView drv in dti.DefaultView)" + Environment.NewLine);
                            sb.Append("				{" + Environment.NewLine);
							sb.Append("					if ((drv.Row.RowState == System.Data.DataRowState.Added || drv.Row.RowState == System.Data.DataRowState.Detached) && jj >= iExist)" + Environment.NewLine);
							sb.Append("					{" + Environment.NewLine);
							sb.Append("						DataTable dtd;" + Environment.NewLine);
						}
                        sb.Append("						dtd = ");
                        if (",AutoComplete,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            // force reload at the start of foreach as in the case of autocomplete, whatever stored in session is invalid as it contains only one item at most
                            sb.Append("jj==iExist ? null : ");
                        }
                        sb.Append("(DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "];" + Environment.NewLine);
                        sb.Append("						if (dtd == null)" + Environment.NewLine);
                        sb.Append("						{" + Environment.NewLine);
						sb.Append("							try" + Environment.NewLine);
						sb.Append("							{" + Environment.NewLine);
                        //sb.Append("								if (Config.Architect == \"W\")" + Environment.NewLine);
                        //sb.Append("								{" + Environment.NewLine);
                        //sb.Append("									dtd = XmlUtils.XmlToDataTable(" + dw["ProgramName"].ToString() + "Facade().GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "(" + screenId.ToString() + ",true,0,string.Empty" + Robot.GetCnCall(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,XmlUtils.ObjectToXml(base.LImpr),XmlUtils.ObjectToXml(base.LCurr)));" + Environment.NewLine);
                        //sb.Append("								}" + Environment.NewLine);
                        //sb.Append("								else" + Environment.NewLine);
                        //sb.Append("								{" + Environment.NewLine);
                        string sAddNew = ",false";
                        if (drv["DisplayName"].ToString() == "ComboBox" || drv["DisplayName"].ToString() == "DropDownList" || (drv["AllowNulls"].ToString() == "Y" && drv["RequiredValid"].ToString() == "N" && drv["DisplayMode"].ToString() != "Document")) { sAddNew = ",true"; }
                        sb.Append("								dtd = (new AdminSystem()).GetDdl(" + screenId.ToString() + ",\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\"" + sAddNew + ",true,0,string.Empty" + Robot.GetCnStr(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr);" + Environment.NewLine);
                        //sb.Append("									dtd = (new " + dw["ProgramName"].ToString() + "System()).GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "(" + screenId.ToString() + ",true,0,string.Empty" + Robot.GetCnCall(drv["MultiDesignDb"].ToString(), "N") + ",string.Empty,base.LImpr,base.LCurr);" + Environment.NewLine);
                        //sb.Append("								}" + Environment.NewLine);
						sb.Append("							}" + Environment.NewLine);
                        sb.Append("							catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
						sb.Append("							Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "] = dtd;" + Environment.NewLine);
						sb.Append("						}" + Environment.NewLine);
                        string AllowNulls; string ComboBox;
                        if (drv["DisplayName"].ToString() == "ComboBox") { ComboBox = "true"; } else { ComboBox = "false"; }
                        if (drv["ColumnIdentity"].ToString() == "Y") { AllowNulls = "true"; } else if (drv["AllowNulls"].ToString() == "Y") { AllowNulls = "true"; } else { AllowNulls = "false"; }
						sb.Append("						ScrImportDdl(dtd.DefaultView, drv, " + ComboBox + ", \"" + pMKey + "\", \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\", \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\", " + drv["DdlRefColLen"].ToString() + ", \"" + drv["MatchCd"].ToString() + "\", " + AllowNulls + ");" + Environment.NewLine);
                    }
				}
				if (bDdlFound)
				{
					sb.Append("					}" + Environment.NewLine);
					sb.Append("					jj = jj + 1;" + Environment.NewLine);
					sb.Append("				}" + Environment.NewLine);
				}
                sb.Append("				iRow = dti.DefaultView.Count - iExist;" + Environment.NewLine);
                //if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                //{
                //    sb.Append("				if (!(GetAuthRow().Rows[0][\"AllowUpd\"].ToString() == \"N\" && GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"N\") && !(Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))");
                //}
                //else
                //{
                //    sb.Append("				if (GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"Y\")");
                //}
                //sb.Append(" {c" + dw["ProgramName"].ToString() + "Grid_AddNew(dti);}" + Environment.NewLine);
                //sb.Append("				if (!dti.Columns.Contains(\"_CurRow\")) { dti.Columns.Add(\"_CurRow\"); }" + Environment.NewLine);
                sb.Append("				if (!dti.Columns.Contains(\"_NewRow\")) { dti.Columns.Add(\"_NewRow\"); }" + Environment.NewLine);
                sb.Append("				Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dti;" + Environment.NewLine);
				sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_DataBind(dti.DefaultView);" + Environment.NewLine);
				/*
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					sb.Append("				if (!(GetAuthRow().Rows[0][\"AllowUpd\"].ToString() == \"N\" && GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"N\") && !(Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))");
				}
				else
				{
					sb.Append("				if (GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"Y\")");
				}
				sb.Append(" {iRow = iRow - 1;}" + Environment.NewLine);
				*/
				sb.Append("				string msg = iRow.ToString() + \" rows from selected source imported successfully. \" + Session[KEY_cntImpPwdOvride].ToString() + \" rows validated by Password Override. Please press Save button to save to database.\";" + Environment.NewLine);
				sb.Append("				if (Session[\"CtrlAcctList\"] != null)" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					System.Collections.Hashtable ht = (System.Collections.Hashtable) Session[\"CtrlAcctList\"];" + Environment.NewLine);
				sb.Append("					string ss = string.Empty;" + Environment.NewLine);
				sb.Append("					System.Collections.IDictionaryEnumerator de = ht.GetEnumerator();" + Environment.NewLine);
				sb.Append("					while ( de.MoveNext() )" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				sb.Append("						ss = ss + de.Key + \" (\" + de.Value.ToString() + \"), \";" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("					msg = msg + \" List of Password Override items: \" + ss.Remove(ss.Length - 2, 2) + \".\";" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("				Session.Remove(KEY_scrImport); Session.Remove(\"CtrlAcctList\");" + Environment.NewLine);
				sb.Append("				cImportPwd.Text = string.Empty;" + Environment.NewLine);
				sb.Append("				ShowDirty(true);" + Environment.NewLine);
				sb.Append("				Session[KEY_lastImpPwdOvride] = 0; Session[KEY_cntImpPwdOvride] = 0;" + Environment.NewLine);
                sb.Append("				bInfoNow.Value = \"Y\"; PreMsgPopup(msg);" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cContinueButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Continue")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Continue")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (before) Web Rule starts here *** //" + Environment.NewLine); }
					sb.Append("			ScrImport(false);" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Continue")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (after) Web Rule starts here *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		protected void cBrowseButton_Click(object sender, EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
                sb.Append("			if (cBrowse.HasFile && cBrowse.PostedFile.FileName != string.Empty)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
                sb.Append("				string fileAndPath = cBrowse.PostedFile.FileName;" + Environment.NewLine);
                sb.Append("				string fNameO = string.Empty;" + Environment.NewLine);
                sb.Append("				try {" + Environment.NewLine);
                sb.Append("				    foreach (var c in Path.GetInvalidPathChars()) { fileAndPath = fileAndPath.Replace(c, '_'); }" + Environment.NewLine);
                sb.Append("				    fNameO = Path.GetFileName(fileAndPath);" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
                sb.Append("				catch (Exception err) {" + Environment.NewLine);
                sb.Append("				    bErrNow.Value = \"Y\"; PreMsgPopup(\"Invalid characters in file and/or path \\\"\" + fileAndPath + \"\\\": \" + err.Message);" + Environment.NewLine);
                sb.Append("				    return;" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
                sb.Append("				try {" + Environment.NewLine);
				sb.Append("					string fName;" + Environment.NewLine);
				sb.Append("					if (fNameO.LastIndexOf(\".\") >= 0)" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				sb.Append("						fName = fNameO.Insert(fNameO.LastIndexOf(\".\"), \"_\" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString());" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("					else" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				sb.Append("						fName = fNameO + \"_\" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
                sb.Append("					fName = fName.Replace(\":\",\"\").Replace(\"..\",\"\");" + Environment.NewLine);
                sb.Append("					if (!Directory.Exists(Config.PathTmpImport)) { Directory.CreateDirectory(Config.PathTmpImport); }" + Environment.NewLine);
                sb.Append("					cBrowse.PostedFile.SaveAs(Config.PathTmpImport + fName);" + Environment.NewLine);
                sb.Append("					cWorkSheet.DataSource = (new XLSImport(Config.WsXlsUrl)).GetSheetNames(Config.PathTmpImport + fName); cWorkSheet.DataBind();" + Environment.NewLine);
				sb.Append("					cFNameO.Text = fNameO; cFName.Text = fName;" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
                sb.Append("				catch (Exception err) {bErrNow.Value = \"Y\"; PreMsgPopup(\"Unable to retrieve sheet names from \\\"\" + fNameO + \"\\\": \" + err.Message); }" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cImportButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Import")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Import")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
					sb.Append("			if (cFNameO.Text != string.Empty && cWorkSheet.Items.Count > 0 && cWorkSheet.SelectedItem.Text != string.Empty && cStartRow.Text != string.Empty)" + Environment.NewLine);
					sb.Append("			{" + Environment.NewLine);
					sb.Append("				DataTable dt" + dw["ProgramName"].ToString() + "Grid = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
					sb.Append("				try" + Environment.NewLine);
					sb.Append("				{" + Environment.NewLine);
                    sb.Append("					if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || UpdateGridRow(c" + dw["ProgramName"].ToString() + "Grid, new CommandEventArgs(\"Save\", \"\")))" + Environment.NewLine);
					sb.Append("					{" + Environment.NewLine);
                    //sb.Append("						if (dt" + dw["ProgramName"].ToString() + "Grid.Columns.Contains(\"_LastRow\") && dt" + dw["ProgramName"].ToString() + "Grid.DefaultView[dt" + dw["ProgramName"].ToString() + "Grid.DefaultView.Count - 1][\"_LastRow\"].ToString() == \"Y\")" + Environment.NewLine);
                    //sb.Append("						{" + Environment.NewLine);
                    //sb.Append("							dt" + dw["ProgramName"].ToString() + "Grid.DefaultView.Delete(dt" + dw["ProgramName"].ToString() + "Grid.DefaultView.Count - 1);" + Environment.NewLine);
                    //sb.Append("						}" + Environment.NewLine);
					sb.Append("						Session[KEY_scrImport] = ImportFile(dt" + dw["ProgramName"].ToString() + "Grid.Copy(),cFNameO.Text,cWorkSheet.SelectedItem.Text,cStartRow.Text,Config.PathTmpImport + cFName.Text);" + Environment.NewLine);
					sb.Append("					}" + Environment.NewLine);
					sb.Append("					cHideImpButton_Click(sender,new EventArgs());" + Environment.NewLine);
					sb.Append("				}" + Environment.NewLine);
                    sb.Append("				catch (Exception err) {bErrNow.Value = \"Y\"; PreMsgPopup(\"Error in spreadsheet \\\"\" + cFNameO.Text + \"\\\":<br>\" + err.Message); return; }" + Environment.NewLine);
					sb.Append("				finally {cWorkSheet.Items.Clear();}" + Environment.NewLine);
					// Do not "File.Delete(Config.PathTmpImport + cFName.Text);" because Excel-97/network spreadsheets may hang the process saying file-still-open-by-another-process.
					sb.Append("				ScrImport(false);" + Environment.NewLine);
					sb.Append("			}" + Environment.NewLine);
					sb.Append("			else" + Environment.NewLine);
					sb.Append("			{" + Environment.NewLine);
                    sb.Append("				bInfoNow.Value = \"Y\"; PreMsgPopup(\"Please select a spreadsheet, then a worksheet, indicate the starting row and try again.\");" + Environment.NewLine);
					sb.Append("			}" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Import")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
                }
				sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		private DataTable ImportFile(DataTable dt, string fileName, string workSheet, string startRow, string fileFullName)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                sb.Append("			try" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
                sb.Append("				DataTable dtImp = RO.Common3.XmlUtils.XmlToDataSet((new XLSImport(Config.WsXlsUrl)).ImportFile(fileName,workSheet,startRow,fileFullName)).Tables[0];" + Environment.NewLine);
                sb.Append("				DataRowCollection rows = dtImp.Rows;" + Environment.NewLine);
                sb.Append("				DataColumnCollection cols = dt.Columns;" + Environment.NewLine);
                sb.Append("				Func<string, string, bool> isDateCol = (cl, c) => (\",\" + cl + \",\").IndexOf(\",\" + c + \",\") >= 0;" + Environment.NewLine);
                sb.Append("				Func<string, string, bool> isDateUTCCol = (cl, c) => (\",\" + cl + \",\").IndexOf(\",\" + c + \",\") >= 0;" + Environment.NewLine);
                sb.Append("				string ss;" + Environment.NewLine);
                sb.Append("				int iStart = int.Parse(startRow) - 1;" + Environment.NewLine);
                sb.Append("				int idv = dt.Rows.Count;" + Environment.NewLine);
                sb.Append("				int idel = 0;" + Environment.NewLine);
                sb.Append("				System.Collections.Generic.List<string> ErrLst = new System.Collections.Generic.List<string>();" + Environment.NewLine);
                sb.Append("				bool bHasErr = false;" + Environment.NewLine);
                sb.Append("				for ( int iRow = iStart; iRow < rows.Count; iRow++ )" + Environment.NewLine);
                sb.Append("				{" + Environment.NewLine);
                sb.Append("					if (");
                int iNotNull = 0;
                int iImportCol = 0;
                System.Collections.Generic.List<string> dateCol = new System.Collections.Generic.List<string>();
                System.Collections.Generic.List<string> dateUTCCol = new System.Collections.Generic.List<string>();
                bool bNotNullFound = false;
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = "MasterTable = 'Y'"; }
                StringBuilder sbColumnDefault = new StringBuilder();
                foreach (DataRowView drv in dv)
                {
                    if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y" && ",TextBox,ComboBox,DropDownList,ListBox,RadioButtonList,CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        sbColumnDefault.Append("						if (rows[iRow][" + iImportCol.ToString() + "].ToString() == string.Empty");
                        if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        {
                            sbColumnDefault.Append(" && rows[iRow][" + (iImportCol + 1).ToString() + "].ToString() == string.Empty");
                        }
                        sbColumnDefault.Append(") { rows[iRow][" + iImportCol.ToString() + "] = ");
                        if (",LongDate,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            try { DateTime.Parse(drv["DefaultValue"].ToString()); sbColumnDefault.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToLongDateString();"); }
                            catch { sbColumnDefault.Append(drv["DefaultValue"].ToString() + ".ToLongDateString();"); }
                        }
                        else if (",LongDateTime,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            try { DateTime.Parse(drv["DefaultValue"].ToString()); sbColumnDefault.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"f\");"); }
                            catch { sbColumnDefault.Append(drv["DefaultValue"].ToString() + ".ToString(\"f\");"); }
                        }
                        else if (",LongDateTimeUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            try { DateTime.Parse(drv["DefaultValue"].ToString()); sbColumnDefault.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"f\");"); }
                            catch { sbColumnDefault.Append(drv["DefaultValue"].ToString() + ".ToUniversalTime().ToString(\"f\");"); }
                        }
                        else if (",DateTimeUTC,ShortDateTimeUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            try { DateTime.Parse(drv["DefaultValue"].ToString()); sbColumnDefault.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"g\");"); }
                            catch { sbColumnDefault.Append(drv["DefaultValue"].ToString() + ".ToUniversalTime().ToString(\"g\");"); }
                        }
                        else if (",ShortDateTime,DateTime,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            try { DateTime.Parse(drv["DefaultValue"].ToString()); sbColumnDefault.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToString(\"g\");"); }
                            catch { sbColumnDefault.Append(drv["DefaultValue"].ToString() + ".ToString(\"g\");"); }
                        }
                        else if (",ShortDate,Date,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            try { DateTime.Parse(drv["DefaultValue"].ToString()); sbColumnDefault.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToShortDateString();"); }
                            catch { sbColumnDefault.Append(drv["DefaultValue"].ToString() + ".ToShortDateString();"); }
                        }
                        else if (",DateUTC,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                        {
                            try { DateTime.Parse(drv["DefaultValue"].ToString()); sbColumnDefault.Append("Convert.ToDateTime(\"" + drv["DefaultValue"].ToString() + "\").ToShortDateString();"); }
                            catch { sbColumnDefault.Append(drv["DefaultValue"].ToString() + ".ToUniversalTime().ToShortDateString();"); }
                        }
                        else
                        {
                            sbColumnDefault.Append(Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + ";");
                        }
                        sbColumnDefault.Append("}" + Environment.NewLine);
                    }
                    if (drv["AllowNulls"].ToString() == "N" && drv["ColumnIdentity"].ToString() == "N" && ",TextBox,ComboBox,DropDownList,ListBox,RadioButtonList,CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        if (bNotNullFound) { sb.Append(" && "); } else { bNotNullFound = true; }
                        sb.Append("rows[iRow][" + iNotNull.ToString() + "].ToString() == string.Empty");
                    }
                    iNotNull = iNotNull + 1;
                    if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        if (drv["AllowNulls"].ToString() == "N" && drv["ColumnIdentity"].ToString() == "N")
                        {
                            sb.Append(" && rows[iRow][" + iNotNull.ToString() + "].ToString() == string.Empty");
                        }
                        iNotNull = iNotNull + 1;
                        iImportCol = iImportCol + 1;
                    }
                    else if (drv["DisplayMode"].ToString().Contains("Date"))
                    {
                        dateCol.Add(iImportCol.ToString());
                        if (drv["DisplayMode"].ToString().Contains("UTC")) dateUTCCol.Add(iImportCol.ToString());
                    }
                    iImportCol = iImportCol + 1;
                }
                if (!bNotNullFound) { throw new Exception(screenTitle + ": SpreadSheet import must have at least one non-nullable column that is not the identity column. Please try again."); }
                sb.Append(") {idel = idel + 1;}" + Environment.NewLine);
                sb.Append("					else" + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
				sb.Append("						dt.Rows.Add(dt.NewRow());" + Environment.NewLine);
                if (sbColumnDefault.Length > 0) sb.Append(sbColumnDefault.ToString());
                sb.Append("						for ( int iCol = 0; iCol < cols.Count; iCol++ )" + Environment.NewLine);
                sb.Append("						{" + Environment.NewLine);
                sb.Append("							try { ss = rows[iRow][iCol].ToString().Trim(); } catch { ss = string.Empty; }" + Environment.NewLine);
                sb.Append("							try {" + Environment.NewLine);
                sb.Append("							    if (!string.IsNullOrEmpty(ss)) {" + Environment.NewLine);
                sb.Append("							        dt.Rows[iRow - iStart - idel + idv][iCol] = isDateCol(\"\", iCol.ToString()) ? base.ToIntDateTime(ss, isDateUTCCol(\"\", iCol.ToString()), true) : ss;" + Environment.NewLine);
                sb.Append("							    }" + Environment.NewLine);
                sb.Append("							}" + Environment.NewLine);
                sb.Append("							catch (Exception ex) {" + Environment.NewLine);
                sb.Append("							    if (ss.EndsWith(\"%\")) {" + Environment.NewLine);
                sb.Append("							        try { dt.Rows[iRow - iStart - idel + idv][iCol] = ss.Left(ss.Length - 1); } catch { }" + Environment.NewLine);
                sb.Append("							    }" + Environment.NewLine);
                sb.Append("							    else {" + Environment.NewLine);
                sb.Append("							        bHasErr = true;" + Environment.NewLine);
                sb.Append("							        ErrLst.Add(\"Row \" + (iRow + 1).ToString() + \" Col \" + Utils.Num2ExcelCol(iCol + 1) + \": \" + Server.HtmlEncode(ex.Message));" + Environment.NewLine);
                sb.Append("							    }" + Environment.NewLine);
                sb.Append("							}" + Environment.NewLine);
                //sb.Append("							try { ss = rows[iRow][iCol].ToString(); } catch { ss = string.Empty; }" + Environment.NewLine);
                //sb.Append("							try { dt.Rows[iRow - iStart - idel + idv][iCol] = isDateCol(\"" + string.Join(",", dateCol.ToArray()) + "\",iCol.ToString()) ? base.ToIntDateTime(ss," + "isDateUTCCol(\"" + string.Join(",", dateUTCCol.ToArray()) + "\",iCol.ToString())" + ",true) : ss; }" + Environment.NewLine);
                //sb.Append("						    catch { if (ss.EndsWith(\"%\")) { try { dt.Rows[iRow - iStart - idel + idv][iCol] = ss.Left(ss.Length - 1); } catch { } } }" + Environment.NewLine);
                sb.Append("						}" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
                sb.Append("				if (bHasErr) { throw new Exception(string.Join(\"<br>\", ErrLst)); }" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
                sb.Append("			catch(Exception e) { throw (e); }" + Environment.NewLine);
                sb.Append("			return dt;" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
				sb.Append("		private void GotoPage(int pageNo)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
                sb.Append("			if (pageNo >= 0 && pageNo < GetTotalPages())" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
                sb.Append("				if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || UpdateGridRow(c" + dw["ProgramName"].ToString() + "Grid, new CommandEventArgs(\"Save\", \"\")))" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
                sb.Append("					try { c" + dw["ProgramName"].ToString() + "GridDataPager.SetPageProperties(c" + dw["ProgramName"].ToString() + "GridDataPager.PageSize * pageNo, c" + dw["ProgramName"].ToString() + "GridDataPager.MaximumRows, false); c" + dw["ProgramName"].ToString() + "Grid_DataBind(null); }" + Environment.NewLine);
				sb.Append("					catch" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
                sb.Append("						try { c" + dw["ProgramName"].ToString() + "GridDataPager.SetPageProperties(0, c" + dw["ProgramName"].ToString() + "GridDataPager.MaximumRows, false); c" + dw["ProgramName"].ToString() + "Grid_DataBind(null); } catch {}" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
                sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnItemCommand(object sender, ListViewCommandEventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		private void c" + dw["ProgramName"].ToString() + "Grid_DataBind(DataView dv" + dw["ProgramName"].ToString() + "Grid)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			if (dv" + dw["ProgramName"].ToString() + "Grid == null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
				sb.Append("				dv" + dw["ProgramName"].ToString() + "Grid = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
				sb.Append("			if (dv" + dw["ProgramName"].ToString() + "Grid != null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
                sb.Append("				LcAuth = GetAuthCol().AsEnumerable().ToDictionary<DataRow,string>(dr=>dr[\"ColName\"].ToString());" + Environment.NewLine);
                sb.Append("				c" + dw["ProgramName"].ToString() + "Grid.DataSource = dv" + dw["ProgramName"].ToString() + "Grid;" + Environment.NewLine);
				sb.Append("				c" + dw["ProgramName"].ToString() + "Grid.DataBind();" + Environment.NewLine);
                sb.Append("				int totalPages = GetTotalPages(); if (totalPages <= 0) { totalPages = 1; }" + Environment.NewLine);
                sb.Append("				cPageNoLabel.Text = \" of \" + totalPages.ToString(); cGoto.Text = (GetCurrPageIndex() + 1).ToString();" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
                sb.Append("			if (cFindFilter.Items.Count <= 0)" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
                sb.Append("				DataTable dtAuth = GetAuthCol();" + Environment.NewLine);
                sb.Append("				DataTable dtLabel = GetLabel();" + Environment.NewLine);
                sb.Append("				int ii = 0;" + Environment.NewLine);
                sb.Append("				ListItem li = new ListItem();" + Environment.NewLine);
                sb.Append("				li.Value = string.Empty; li.Text = \"All\";" + Environment.NewLine);
                sb.Append("				cFindFilter.Items.Add(li);" + Environment.NewLine);
                sb.Append("				foreach (DataRow dr in dtLabel.Rows)" + Environment.NewLine);
                sb.Append("				{" + Environment.NewLine);
                sb.Append("					if (ii >= " + iOffset.ToString() + " && !string.IsNullOrEmpty(dr[\"ColumnHeader\"].ToString()) && !string.IsNullOrEmpty(dr[\"TableId\"].ToString()) && dtAuth.Rows[ii][\"ColVisible\"].ToString() == \"Y\")" + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
                sb.Append("						li = new ListItem();" + Environment.NewLine);
                sb.Append("						li.Value = ii.ToString(); li.Text = dr[\"ColumnHeader\"].ToString().Replace(\"*\", string.Empty);" + Environment.NewLine);
                sb.Append("						cFindFilter.Items.Add(li);" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                sb.Append("					ii = ii + 1;" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
                if (dw["ShowGridHead"].ToString() == "N")
                {
                    sb.Append("			if (cSortFilter.Items.Count <= 0)" + Environment.NewLine);
                    sb.Append("			{" + Environment.NewLine);
                    sb.Append("				DataTable dtAuth = GetAuthCol();" + Environment.NewLine);
                    sb.Append("				DataTable dtLabel = GetLabel();" + Environment.NewLine);
                    sb.Append("				int ii = 0;" + Environment.NewLine);
                    sb.Append("				ListItem li = new ListItem();" + Environment.NewLine);
                    sb.Append("				li.Value = string.Empty; li.Text = string.Empty;" + Environment.NewLine);
                    sb.Append("				cSortFilter.Items.Add(li);" + Environment.NewLine);
                    sb.Append("				foreach (DataRow dr in dtLabel.Rows)" + Environment.NewLine);
                    sb.Append("				{" + Environment.NewLine);
                    sb.Append("					if (ii >= " + iOffset.ToString() + " && !string.IsNullOrEmpty(dr[\"ColumnHeader\"].ToString()) && !string.IsNullOrEmpty(dr[\"TableId\"].ToString()) && dtAuth.Rows[ii][\"ColVisible\"].ToString() == \"Y\")" + Environment.NewLine);
                    sb.Append("					{" + Environment.NewLine);
                    sb.Append("						li = new ListItem();" + Environment.NewLine);
                    sb.Append("						li.Value = ii.ToString(); li.Text = dr[\"ColumnHeader\"].ToString().Replace(\"*\", string.Empty);" + Environment.NewLine);
                    sb.Append("						cSortFilter.Items.Add(li);" + Environment.NewLine);
                    sb.Append("					}" + Environment.NewLine);
                    sb.Append("					ii = ii + 1;" + Environment.NewLine);
                    sb.Append("				}" + Environment.NewLine);
                    sb.Append("			}" + Environment.NewLine);
                }
                sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
                if (dw["ShowGridHead"].ToString() == "N")
                {
                    sb.Append(Environment.NewLine);
                    sb.Append("        protected void cSortFilter_SelectedIndexChanged(object sender, System.EventArgs e)" + Environment.NewLine);
                    sb.Append("        {" + Environment.NewLine);
                    sb.Append("            cSortImg.Visible = true;" + Environment.NewLine);
                    sb.Append("            Session.Remove(KEY_lastSortUrl); Session[KEY_lastSortTog] = \"Y\"; Session[KEY_lastSortCol] = \"0\";" + Environment.NewLine);
                    sb.Append("            if (!string.IsNullOrEmpty(cSortFilter.SelectedValue))" + Environment.NewLine);
                    sb.Append("            {" + Environment.NewLine);
                    sb.Append("                Session[KEY_lastSortExp] = ((DataTable)GetAuthCol()).Rows[int.Parse(cSortFilter.SelectedValue)][\"ColName\"].ToString();" + Environment.NewLine);
                    sb.Append("                c" + dw["ProgramName"].ToString() + "Grid_OnSorting(sender, new ListViewSortEventArgs((string)Session[KEY_lastSortExp], SortDirection.Ascending));" + Environment.NewLine);
                    sb.Append("            }" + Environment.NewLine);
                    sb.Append("            else" + Environment.NewLine);
                    sb.Append("            {" + Environment.NewLine);
                    sb.Append("                Session.Remove(KEY_lastSortExp);" + Environment.NewLine);
                    sb.Append("                c" + dw["ProgramName"].ToString() + "Grid_OnSorting(sender, new ListViewSortEventArgs(string.Empty, SortDirection.Ascending));" + Environment.NewLine);
                    sb.Append("            }" + Environment.NewLine);
                    sb.Append("        }" + Environment.NewLine);
                    sb.Append(Environment.NewLine);
                    sb.Append("        protected void cSortImg_Click(object sender, System.Web.UI.ImageClickEventArgs e)" + Environment.NewLine);
                    sb.Append("        {" + Environment.NewLine);
                    sb.Append("            if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != \"0\") { Session.Remove(KEY_lastSortUrl); }" + Environment.NewLine);
                    sb.Append("            Session[KEY_lastSortTog] = \"Y\"; Session[KEY_lastSortCol] = \"0\";" + Environment.NewLine);
                    sb.Append("            if (!string.IsNullOrEmpty(cSortFilter.SelectedValue))" + Environment.NewLine);
                    sb.Append("            {" + Environment.NewLine);
                    sb.Append("                Session[KEY_lastSortExp] = ((DataTable)GetAuthCol()).Rows[int.Parse(cSortFilter.SelectedValue)][\"ColName\"].ToString();" + Environment.NewLine);
                    sb.Append("                c" + dw["ProgramName"].ToString() + "Grid_OnSorting(sender, new ListViewSortEventArgs((string)Session[KEY_lastSortExp], SortDirection.Ascending));" + Environment.NewLine);
                    sb.Append("            }" + Environment.NewLine);
                    sb.Append("        }" + Environment.NewLine);
                }
                sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnSorting(object sender, ListViewSortEventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
				sb.Append("			DataView dv = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
				sb.Append("			if (dv != null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
                sb.Append("				if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || UpdateGridRow(c" + dw["ProgramName"].ToString() + "Grid, new CommandEventArgs(\"Save\", \"\")))" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					string ftr = string.Empty;" + Environment.NewLine);
                //if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                //{
                //    sb.Append("					if (!(GetAuthRow().Rows[0][\"AllowUpd\"].ToString() == \"N\" && GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"N\") && !(Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))");
                //}
                //else
                //{
                //    sb.Append("					if (GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"Y\")");
                //}
                //sb.Append(" {dv.Delete(dv.Count-1);}" + Environment.NewLine);
                sb.Append("					if (!dv.Table.Columns.Contains(\"_SortOrder\")) { dv.Table.Columns.Add(\"_SortOrder\"); }" + Environment.NewLine);
                sb.Append("					if (dv.RowFilter != string.Empty) { ftr = dv.RowFilter; dv.RowFilter = string.Empty; }" + Environment.NewLine);
                sb.Append("					if (Session[KEY_lastSortUrl] == null)   // First time." + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
                sb.Append("					    dv.Sort = \"_SortOrder DESC, \" + e.SortExpression; Session[KEY_lastSortUrl] = \"~/images/ArrowUp.png\";");
                if (dw["ShowGridHead"].ToString() == "N") { sb.Append(" cSortImg.ImageUrl = \"~/images/Asce.png\";"); }
                sb.Append(" Session[KEY_lastSortTog] = \"N\";" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                sb.Append("					else if ((string)Session[KEY_lastSortTog] == \"Y\")" + Environment.NewLine);
                sb.Append("					{" + Environment.NewLine);
                sb.Append("					    if (((string)Session[KEY_lastSortUrl]).IndexOf(\"ArrowDn\") >= 0)" + Environment.NewLine);
                sb.Append("					    {" + Environment.NewLine);
                sb.Append("							dv.Sort = \"_SortOrder DESC, \" + e.SortExpression; Session[KEY_lastSortUrl] = \"~/images/ArrowUp.png\";");
                if (dw["ShowGridHead"].ToString() == "N") { sb.Append(" cSortImg.ImageUrl = \"~/images/Asce.png\";"); }
                sb.Append(Environment.NewLine);
                sb.Append("					    }" + Environment.NewLine);
                sb.Append("					    else" + Environment.NewLine);
                sb.Append("					    {" + Environment.NewLine);
                sb.Append("							dv.Sort = \"_SortOrder DESC, \" + e.SortExpression + \" DESC\"; Session[KEY_lastSortUrl] = \"~/images/ArrowDn.png\";");
                if (dw["ShowGridHead"].ToString() == "N") { sb.Append(" cSortImg.ImageUrl = \"~/images/Desc.png\";"); }
                sb.Append(Environment.NewLine);
                sb.Append("					    }" + Environment.NewLine);
                sb.Append("					    Session[KEY_lastSortTog] = \"N\";" + Environment.NewLine);
                sb.Append("					}" + Environment.NewLine);
                sb.Append("					else if (((string)Session[KEY_lastSortUrl]).IndexOf(\"ArrowDn\") >= 0) { dv.Sort = \"_SortOrder DESC, \" + e.SortExpression + \" DESC\"; } else { dv.Sort = \"_SortOrder DESC, \" + e.SortExpression; }" + Environment.NewLine);
                //sb.Append("					if (!dv.Table.Columns.Contains(\"_SortOrder\")) {dv.Table.Columns.Add(\"_SortOrder\");}" + Environment.NewLine);
                //sb.Append("					int ii = 0; foreach (DataRowView drv in dv) {ii = ii + 1; drv[\"_SortOrder\"] = ii.ToString().PadLeft(6,(char)48);}" + Environment.NewLine);
                //sb.Append("					Session[KEY_lastSortOrd] = ii.ToString().PadLeft(6,(char)48);" + Environment.NewLine);
                sb.Append("					ViewState[\"_SortColumn\"] = dv.Sort;" + Environment.NewLine);
                //if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                //{
                //    sb.Append("					if (!(GetAuthRow().Rows[0][\"AllowUpd\"].ToString() == \"N\" && GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"N\") && !(Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))");
                //}
                //else
                //{
                //    sb.Append("					if (GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"Y\")");
                //}
                //sb.Append(" {c" + dw["ProgramName"].ToString() + "Grid_AddNew(dv.Table);}" + Environment.NewLine);
				sb.Append("					if (ftr != string.Empty) { dv.RowFilter = ftr; }" + Environment.NewLine);
				sb.Append("					Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dt;" + Environment.NewLine);
				sb.Append("					c" + dw["ProgramName"].ToString() + "Grid_DataBind(dv);" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
                sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnPagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
                sb.Append("		    c" + dw["ProgramName"].ToString() + "GridDataPager.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);" + Environment.NewLine);
                sb.Append("		    DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                sb.Append("		    DataView dv = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
                sb.Append("			c" + dw["ProgramName"].ToString() + "Grid_DataBind(dv); c" + dw["ProgramName"].ToString() + "Grid.EditIndex = -1;" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		private void GridChkPgDirty(ListViewItem lvi)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                sb.Append("				WebControl cc = null;");
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = "MasterTable = 'Y'"; }
                foreach (DataRowView drv in dv)
                {
                    if (PopTextBox(drv)) { sb.Append(" System.Web.UI.WebControls.Image ib = null;"); break; }
                }
                sb.Append(Environment.NewLine);
                foreach (DataRowView drv in dv)
                {
                    if (drv["ColumnIdentity"].ToString() != "Y" && (",Button,ImageButton,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString())))
                    {
                        if (",CheckBox,RadioButtonList,Calendar,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sEvent = "OnClick"; } else { sEvent = "OnChange"; }
                        sb.Append("				cc = ((WebControl)lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"));" + Environment.NewLine);
                        sb.Append("				if ((cc.Attributes[\"" + sEvent + "\"] == null || cc.Attributes[\"" + sEvent + "\"].IndexOf(\"ChkPgDirty\") < 0) && cc.Visible && cc.Enabled) {cc.Attributes[\"" + sEvent + "\"] += \"document.getElementById('\" + bPgDirty.ClientID + \"').value='Y'; ChkPgDirty();");
                        if (",CheckBox,RadioButtonList,Calendar,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append(" this.focus();"); }
                        if (drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y" || ",ComboBox,ComboBoxNoPunc,Calendar,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "upload")
                        {
                            if (drv["IgnoreConfirm"].ToString() == "Y") sb.Append(" document.getElementById('\" + bConfirm.ClientID + \"').value='N';");
                            else sb.Append(" return CanPostBack(true,this);");
                        }
                        sb.Append("\";}");
                        if (drv["IgnoreConfirm"].ToString() != "Y")
                        {
                            sb.Append(" cc.Attributes[\"NeedConfirm\"] = \"Y\";");
                        }
                        sb.Append(Environment.NewLine);
                    }
                    if (drv["DisplayMode"].ToString().ToLower() == "upload")
                    {
                        sb.Append("				cc = ((WebControl)lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo\"));" + Environment.NewLine);
                        sb.Append("				if (cc.Attributes[\"OnClick\"] == null || cc.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cc.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
                    }
                    if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                    {
                        sb.Append("				cc = ((WebControl)lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + (drv["DisplayName"].ToString() == "ImageButton" ? "" : "Search") + "\"));" + Environment.NewLine);
                        sb.Append("				if (cc.Attributes[\"OnClick\"] == null || cc.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cc.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
                    }
                    if (drv["PwdOvride"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        sb.Append("				cc = ((WebControl)lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd\"));" + Environment.NewLine);
                        sb.Append("				if (cc.Attributes[\"OnChange\"] == null || cc.Attributes[\"OnChange\"].IndexOf(\"_bConfirm\") < 0) {cc.Attributes[\"OnChange\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
                    }
                    if (PopTextBox(drv))
                    {
                        sb.Append("				ib = ((System.Web.UI.WebControls.Image)lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "E\"));" + Environment.NewLine);
                        sb.Append("				ib.Attributes[\"target_id\"] = cc.ClientID;" + Environment.NewLine);
                    }
                }
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnItemDataBound(object sender, ListViewItemEventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
                bool bAggregate = false;
                bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "ITMDTR")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "ITMDTB")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** GridItemDataBound (before) Web Rule End *** //" + Environment.NewLine); }
					// Edit controls not available at event c???Grid_EditCommand().
					sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                    sb.Append("			bool isEditItem = false;" + Environment.NewLine);
                    bool hasImageColumn = dv.Cast<DataRowView>()
                            .Where(drv=>drv["DisplayName"].ToString().ToLower() == "imagebutton" 
                                    && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary").Count() > 0;
                    if (hasImageColumn)
                    {
                        sb.Append("			bool isImage = true;" + Environment.NewLine);
                        sb.Append("			bool hasImageContent = false;" + Environment.NewLine);
                    }
                    sb.Append("			DataView dv" + dw["ProgramName"].ToString() + "Grid = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
                    sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex > -1 && GetDataItemIndex(c" + dw["ProgramName"].ToString() + "Grid.EditIndex) == e.Item.DataItemIndex)" + Environment.NewLine);
                    sb.Append("			{" + Environment.NewLine);
                    sb.Append("				isEditItem = true;" + Environment.NewLine);
                    sb.Append("				base.SetGridEnabled(e.Item, GetAuthCol(), GetLabel(), " + iOffset.ToString() + ");" + Environment.NewLine);
                    bool firstCBox = true;
					if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = "MasterTable = 'Y'"; }
					foreach (DataRowView drv in dv)
					{
						if (drv["AggregateCd"].ToString() != string.Empty) { bAggregate = true; }
						if (drv["ColumnIdentity"].ToString() != "Y")
						{
							if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
							{
								sb.Append("				");
                                if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
                                {
                                    sb.Append("if (dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() != string.Empty) {");
                                }
								sb.Append("Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "((");
								if (drv["DisplayName"].ToString() == "ComboBox") { sb.Append("RoboCoder.WebControls.ComboBox"); } else sb.Append(drv["DisplayName"].ToString());
                                sb.Append(")e.Item.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"),dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString()");
								if (drv["DdlFtrColumnId"].ToString() != string.Empty)
								{
									dvs.RowFilter = string.Empty;
									foreach (DataRowView drvs in dvs)
									{
										if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
										{
											if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drvs["MasterTable"].ToString() == "Y")
											{
												sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
												if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0) { sb.Append("SelectedValue"); } else { sb.Append("Text"); }
											}
											else
											{
                                                sb.Append(",dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString()");
											}
										}
									}
								}
                                if (("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 || ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")) && drv["DisplayName"].ToString() == "ComboBox")
                                {
                                    sb.Append(", e.Item");
                                }
                                sb.Append(");");
                                if (drv["DefaultValue"].ToString() != string.Empty && drv["DefAfter"].ToString() != "Y")
								{
                                    sb.Append("} else");
									sb.Append(" {Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "((");
									if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("TextBox"); }
									else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
									else { sb.Append(drv["DisplayName"].ToString()); }
									sb.Append(")e.Item.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"),");
                                    sb.Append(Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, "String", drv["DefaultValue"].ToString()));
									if (drv["DdlFtrColumnId"].ToString() != string.Empty)
									{
										dvs.RowFilter = string.Empty;
										foreach (DataRowView drvs in dvs)
										{
											if (drvs["ColumnId"].ToString() == drv["DdlFtrColumnId"].ToString())
											{
												if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drvs["MasterTable"].ToString() == "Y")
												{
													sb.Append(",c" + drvs["ColumnName"].ToString() + drvs["TableId"].ToString() + ".");
													if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drvs["DisplayName"].ToString() + ",") >= 0) { sb.Append("SelectedValue"); } else { sb.Append("Text"); }
												}
												else
												{
                                                    sb.Append(",dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + drvs["ColName"].ToString() + drvs["TableId"].ToString() + "\"].ToString()");
												}
											}
										}
									}
                                    if (("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 || ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() != "Y")) && drv["DisplayName"].ToString() == "ComboBox")
                                    {
                                        sb.Append(", e.Item");
                                    }
                                    sb.Append(");}");
								}
								sb.Append(Environment.NewLine);
							}
							if (drv["DisplayName"].ToString() == "CheckBox")
							{
								if (firstCBox)
								{
									sb.Append("				CheckBox cb = null;" + Environment.NewLine);
                                    firstCBox = false;
								}
								sb.Append("				cb = (CheckBox)e.Item.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\");" + Environment.NewLine);
								sb.Append("				if (cb != null)" + Environment.NewLine);
								sb.Append("				{" + Environment.NewLine);
                                sb.Append("					cb.Checked = base.GetBool(dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString());" + Environment.NewLine);
								sb.Append("				}" + Environment.NewLine);
							}
						}
					}
                    sb.Append("				GridChkPgDirty(e.Item);" + Environment.NewLine);
                    sb.Append("			}" + Environment.NewLine);
                    sb.Append("			SetClientRule((ListViewDataItem) e.Item,isEditItem);" + Environment.NewLine);
                    sb.Append("			DataTable dtAuthRow = GetAuthRow();" + Environment.NewLine);
                    sb.Append("			if (dtAuthRow != null)" + Environment.NewLine);
                    sb.Append("			{" + Environment.NewLine);
                    sb.Append("				DataRow dr = dtAuthRow.Rows[0];" + Environment.NewLine);
                    sb.Append("			    Control cc = null;" + Environment.NewLine);
                    if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                    {
                        //                        sb.Append("				if ((dr[\"AllowUpd\"].ToString() == \"N\" && dr[\"AllowAdd\"].ToString() == \"N\") || dr[\"ViewOnly\"].ToString() == \"G\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
                        sb.Append("				if (!CanAct('S') || dr[\"ViewOnly\"].ToString() == \"G\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        sb.Append("					cc = e.Item.FindControl(\"c" + dw["ProgramName"].ToString() + "GridDelete\"); if (cc != null) { cc.Visible = false; }" + Environment.NewLine);
                        sb.Append("					cc = e.Item.FindControl(\"c" + dw["ProgramName"].ToString() + "GridEdit\"); if (cc != null) { cc.Visible = false; }" + Environment.NewLine);
                    }
                    else
                    {
                        sb.Append("				if (dr[\"AllowDel\"].ToString() == \"N\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        sb.Append("					cc = e.Item.FindControl(\"c" + dw["ProgramName"].ToString() + "GridDelete\"); if (cc != null) { cc.Visible = false; }" + Environment.NewLine);
                        sb.Append("				}" + Environment.NewLine);
                        //                        sb.Append("				if (dr[\"AllowUpd\"].ToString() == \"N\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
                        sb.Append("				if (!AllowRowEdit(GetAuthRow()" + ",dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + pMKeyColumn + "\"].ToString()" + ") || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        sb.Append("					cc = e.Item.FindControl(\"c" + dw["ProgramName"].ToString() + "GridEdit\"); if (cc != null) { cc.Visible = false; }" + Environment.NewLine);
                    }
                    sb.Append("				}" + Environment.NewLine);
                    sb.Append("				else" + Environment.NewLine);
                    sb.Append("				{" + Environment.NewLine);
                    sb.Append("			        HtmlTableRow tr = e.Item.FindControl(\"c" + dw["ProgramName"].ToString() + "GridRow\") as HtmlTableRow;" + Environment.NewLine);
                    sb.Append("			        LinkButton lb = e.Item.FindControl(\"c" + dw["ProgramName"].ToString() + "GridEdit\") as LinkButton;" + Environment.NewLine);
                    sb.Append("			        if (tr != null && lb != null) { SetDefaultCtrl(tr, lb, string.Empty); }" + Environment.NewLine);
                    sb.Append("				}" + Environment.NewLine);
                    sb.Append("			}" + Environment.NewLine);
                    bool bHasImage = false;
                    foreach (DataRowView drv in dv)
                    {
                        if (drv["DisplayName"].ToString().ToLower() == "imagebutton" && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary") {
                            bHasImage = true;
                        }
                    }

                    int idx = 0;
                    DataView dvX = new DataView(dv.Table);
                    foreach (DataRowView drv in dvX)
                    {
                        if (drv["DisplayName"].ToString().ToLower() == "button" && drv["MasterTable"].ToString() != "Y")
                        {
                            // setup tool tips for button(only grid)
                            sb.Append("			SetGridButtonToolTip(e, \"" + drv["ColumnName"].ToString() + "\",ColumnToolTip(" + idx.ToString() + "));" + Environment.NewLine);
                        }
                        idx = idx + 1;
                    }

                    sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex > -1 && GetDataItemIndex(c" + dw["ProgramName"].ToString() + "Grid.EditIndex) == e.Item.DataItemIndex)" + Environment.NewLine);
                    sb.Append("			{" + Environment.NewLine);
                    if (bHasImage) { sb.Append("			    ImageButton ImageGridDisplay;" + Environment.NewLine); }
                    foreach (DataRowView drv in dv)
                    {
                        if (drv["DisplayName"].ToString().ToLower() == "imagebutton" && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                        {
                            string keyContentColumnName = drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString();
                            keyContentColumnName = !string.IsNullOrEmpty(keyContentColumnName) ? keyContentColumnName : (drv["MasterTable"].ToString() == "Y" ? pMKeyColumn : pDKeyColumn);
                            string pKeyColumnName = drv["ColTblPK"].ToString();
                            pKeyColumnName = !string.IsNullOrEmpty(pKeyColumnName) ? pKeyColumnName : (drv["MasterTable"].ToString() == "Y" ? pMKey : pDKey);
                            string pKeyDbAppDatabase = (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".");
                            string pKeySystemId = drv["SystemId"].ToString();

                            sb.Append("			    try {" + Environment.NewLine);
                            sb.Append("			        string fileContent = RO.Common3.Utils.DecodeFileStream((byte[])dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"]);" + Environment.NewLine);
                            sb.Append("			        hasImageContent = !fileContent.Trim().Equals(string.Empty);" + Environment.NewLine);
//                            sb.Append("			        System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();" + Environment.NewLine);
                            sb.Append("			        FileUploadObj fileInfo = GetImageButtonFileObject(fileContent);" + Environment.NewLine);
                            sb.Append("			        string mimeType = fileInfo.mimeType;" + Environment.NewLine);
                            sb.Append("			        isImage = \"image/gif,image/jpeg,image/png,image/tiff,image/pjpeg,image/x-png\".IndexOf(mimeType) >= 0;" + Environment.NewLine);
                            sb.Append("			    } catch { isImage = hasImageContent; }" + Environment.NewLine);
                            sb.Append("			    ImageGridDisplay = e.Item.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\") as ImageButton;" + Environment.NewLine);
                            if (drv["DdlRefColumnId"].ToString() == string.Empty)
                            {
                                sb.Append("			    ((FileUpload)e.Item.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Fi\")).Attributes[\"onchange\"] = \"if('\" + dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + (drv["MasterTable"].ToString() == "Y" ? pMKeyColumn : pDKeyColumn) + "\"].ToString() + \"'==''){PopDialog('','Please save the record first before upload.','');}else{sendFile(this.files[0],'\" + GetUrlWithQSHash(\"UpLoad.aspx?key=\" + dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + (drv["MasterTable"].ToString() == "Y" ? pMKeyColumn : pDKeyColumn) + "\"].ToString() + \"&tbl=dbo." + drv["TableName"].ToString() + "&knm=" + (drv["MasterTable"].ToString() == "Y" ? pMKey : pDKey) + "&col=" + drv["ColumnName"].ToString() + (string.IsNullOrEmpty(drv["ResizeHeight"].ToString()) ? string.Empty : "&hgt=" + drv["ResizeHeight"].ToString()) + (string.IsNullOrEmpty(drv["ResizeWidth"].ToString()) ? string.Empty : "&wth=" + drv["ResizeWidth"].ToString()) + "&sys=" + pKeySystemId + "\") + \"',refreshUploadCallback(this,'\" + ImageGridDisplay.ClientID + \"')); return false;} \";" + Environment.NewLine);
                                sb.Append("			    ((ImageButton)e.Item.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Del\")).Attributes[\"onclick\"] = \"sendFile('','\" + GetUrlWithQSHash(\"UpLoad.aspx?del=true&key=\" + dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + (drv["MasterTable"].ToString() == "Y" ? pMKeyColumn : pDKeyColumn) + "\"].ToString() + \"&tbl=dbo." + drv["TableName"].ToString() + "&knm=" + (drv["MasterTable"].ToString() == "Y" ? pMKey : pDKey) + "&col=" + drv["ColumnName"].ToString() + (string.IsNullOrEmpty(drv["ResizeHeight"].ToString()) ? string.Empty : "&hgt=" + drv["ResizeHeight"].ToString()) + (string.IsNullOrEmpty(drv["ResizeWidth"].ToString()) ? string.Empty : "&wth=" + drv["ResizeWidth"].ToString()) + "&sys=" + pKeySystemId + "\") + \"',refreshUploadCallback(this,'\" + ImageGridDisplay.ClientID + \"'));return false;\";" + Environment.NewLine);
                            }
                            sb.Append("			    if (!hasImageContent || (hasImageContent && isImage)) {" + Environment.NewLine);
                            sb.Append("			        ImageGridDisplay.OnClientClick = \"PopDialog('','<img src= \\\"\" + (!hasImageContent ?\"images/DefaultImg.png\": GetUrlWithQSHash(\"DnLoad.aspx?key=\" + dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + keyContentColumnName + "\"].ToString() + \"&tbl=dbo." + drv["TableName"].ToString() + "&knm=" + pKeyColumnName + "&col=" + drv["ColumnName"].ToString() + (string.IsNullOrEmpty(drv["ResizeHeight"].ToString()) ? string.Empty : "&hgt=" + drv["ResizeHeight"].ToString()) + (string.IsNullOrEmpty(drv["ResizeWidth"].ToString()) ? string.Empty : "&wth=" + drv["ResizeWidth"].ToString()) + "&sys=" + pKeySystemId + "\")) + \"\\\" />',''); return false;\";" + Environment.NewLine);
                            sb.Append("			    } else {" + Environment.NewLine);
                            sb.Append("			        ImageGridDisplay.OnClientClick = \"window.open('\" + GetUrlWithQSHash(\"DnLoad.aspx?key=\" + dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + keyContentColumnName + "\"].ToString() + \"&tbl=dbo." + drv["TableName"].ToString() + "&knm=" + pKeyColumnName + "&col=" + drv["ColumnName"].ToString() + (string.IsNullOrEmpty(drv["ResizeHeight"].ToString()) ? string.Empty : "&hgt=" + drv["ResizeHeight"].ToString()) + (string.IsNullOrEmpty(drv["ResizeWidth"].ToString()) ? string.Empty : "&wth=" + drv["ResizeWidth"].ToString()) + "&sys=" + pKeySystemId + "\") + \"'); return false;\";" + Environment.NewLine);
                            sb.Append("			    }" + Environment.NewLine);
                        }
                    }
                    sb.Append("			}" + Environment.NewLine);
                    sb.Append("			else" + Environment.NewLine);
                    sb.Append("			{" + Environment.NewLine);
                    if (bHasImage) { sb.Append("			    ImageButton ImageGridDisplay;" + Environment.NewLine); }
                    foreach (DataRowView drv in dv)
                    {
                        if (drv["DisplayName"].ToString().ToLower() == "imagebutton" && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                        {
                            string keyContentColumnName = drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString();
                            keyContentColumnName = !string.IsNullOrEmpty(keyContentColumnName) ? keyContentColumnName : (drv["MasterTable"].ToString() == "Y" ? pMKeyColumn : pDKeyColumn);
                            string pKeyColumnName = drv["ColTblPK"].ToString();
                            pKeyColumnName = !string.IsNullOrEmpty(pKeyColumnName) ? pKeyColumnName : (drv["MasterTable"].ToString() == "Y" ? pMKey : pDKey);
                            string pKeyDbAppDatabase = drv["dbAppDatabase"].ToString();
                            string pKeySystemId = drv["SystemId"].ToString();

                            sb.Append("			    try {" + Environment.NewLine);
                            sb.Append("			        string fileContent = RO.Common3.Utils.DecodeFileStream((byte[])dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"]);" + Environment.NewLine);
                            sb.Append("			        hasImageContent = !fileContent.Trim().Equals(string.Empty);" + Environment.NewLine);
//                            sb.Append("			        System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();" + Environment.NewLine);
                            sb.Append("			        FileUploadObj fileInfo = GetImageButtonFileObject(fileContent);" + Environment.NewLine);
                            sb.Append("			        string mimeType = fileInfo.mimeType;" + Environment.NewLine);
                            sb.Append("			        isImage = \"image/gif,image/jpeg,image/png,image/tiff,image/pjpeg,image/x-png\".IndexOf(mimeType) >= 0;" + Environment.NewLine);
                            sb.Append("			    } catch { isImage = hasImageContent; }" + Environment.NewLine);
                            sb.Append("			    ImageGridDisplay = e.Item.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "l\") as ImageButton;" + Environment.NewLine);
                            sb.Append("			    if (!hasImageContent || (hasImageContent && isImage)) {" + Environment.NewLine);
                            sb.Append("			        ImageGridDisplay.OnClientClick = \"PopDialog('','<img src= \\\"\" + (!hasImageContent? \"images/DefaultImg.png\": GetUrlWithQSHash(\"DnLoad.aspx?key=\" + dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + keyContentColumnName + "\"].ToString() + \"&tbl=dbo." + drv["TableName"].ToString() + "&knm=" + pKeyColumnName + "&col=" + drv["ColumnName"].ToString() + (string.IsNullOrEmpty(drv["ResizeHeight"].ToString()) ? string.Empty : "&hgt=" + drv["ResizeHeight"].ToString()) + (string.IsNullOrEmpty(drv["ResizeWidth"].ToString()) ? string.Empty : "&wth=" + drv["ResizeWidth"].ToString()) + "&sys=" + pKeySystemId + "\")) + \"\\\" />',''); return false;\";" + Environment.NewLine);
                            sb.Append("			    } else {" + Environment.NewLine);
                            sb.Append("			        ImageGridDisplay.OnClientClick = \"window.open('\" + GetUrlWithQSHash(\"DnLoad.aspx?key=\" + dv" + dw["ProgramName"].ToString() + "Grid[e.Item.DataItemIndex][\"" + keyContentColumnName + "\"].ToString() + \"&tbl=dbo." + drv["TableName"].ToString() + "&knm=" + pKeyColumnName + "&col=" + drv["ColumnName"].ToString() + (string.IsNullOrEmpty(drv["ResizeHeight"].ToString()) ? string.Empty : "&hgt=" + drv["ResizeHeight"].ToString()) + (string.IsNullOrEmpty(drv["ResizeWidth"].ToString()) ? string.Empty : "&wth=" + drv["ResizeWidth"].ToString()) + "&sys=" + pKeySystemId + "\") + \"'); return false;\";" + Environment.NewLine);
                            sb.Append("			    }" + Environment.NewLine);
                        }
                    }
                    sb.Append("			}" + Environment.NewLine);
                    bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "ITMDTA")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** GridItemDataBound (after) Web Rule End *** //" + Environment.NewLine); }
				}
				sb.Append("		}" + Environment.NewLine);
				ii = 0;
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dv.RowFilter = "MasterTable <> 'Y'";} else  {dv.RowFilter = "MasterTable = 'Y'";}
				foreach (DataRowView drv in dv)
				{
                    if (",Button,ImageButton,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString()))
                    {
						sb.Append(Environment.NewLine);
						sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hl_Click(object sender, System.EventArgs e)" + Environment.NewLine);
						sb.Append("		{" + Environment.NewLine);
                        sb.Append("			if (Session[KEY_lastSortCol] == null || (string)Session[KEY_lastSortCol] != \"" + ii.ToString() + "\") { Session.Remove(KEY_lastSortUrl); }" + Environment.NewLine);
                        sb.Append("			Session[KEY_lastSortTog] = \"Y\"; Session[KEY_lastSortCol] = \"" + ii.ToString() + "\"; Session[KEY_lastSortExp] = \"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ("DropDownList,ComboBox,ListBox,RadioButtonList".IndexOf(drv["DisplayName"].ToString()) >= 0 ? "Text" : "") + "\";Session[KEY_lastSortImg] = \"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hi\";" + Environment.NewLine);
                        sb.Append("			c" + dw["ProgramName"].ToString() + "Grid_OnSorting(sender, new ListViewSortEventArgs(\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ("DropDownList,ComboBox,ListBox,RadioButtonList".IndexOf(drv["DisplayName"].ToString()) >= 0 ? "Text" : "") + "\", SortDirection.Ascending));" + Environment.NewLine);
						sb.Append("		}" + Environment.NewLine);
						if (drv["DisplayMode"].ToString() == "CheckBoxAll")
						{
							sb.Append(Environment.NewLine);
							sb.Append("		protected void c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hc_CheckedChanged(object sender, System.EventArgs e)" + Environment.NewLine);
							sb.Append("		{" + Environment.NewLine);
							sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                            sb.Append("			if (dt != null && (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"))))" + Environment.NewLine);
							sb.Append("			{" + Environment.NewLine);
							sb.Append("				CheckBox cc = (CheckBox)sender;" + Environment.NewLine);
							sb.Append("				b" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + " = cc.Checked;" + Environment.NewLine);
							sb.Append("				foreach (DataRowView drv in dt.DefaultView)" + Environment.NewLine);
							sb.Append("				{" + Environment.NewLine);
							//sb.Append("					if (dt.Columns.Contains(\"_NotFiltered\")) {dr[\"_NotFiltered\"] =\"Y\";}" + Environment.NewLine);
							sb.Append("					if (cc.Checked) {drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = \"Y\";} else {drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = \"N\";}" + Environment.NewLine);
							sb.Append("				}" + Environment.NewLine);
							sb.Append("				Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dt;" + Environment.NewLine);
							sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_DataBind(dt.DefaultView);" + Environment.NewLine);
							sb.Append("			}" + Environment.NewLine);
							sb.Append("		}" + Environment.NewLine);
						}
					}
					ii = ii + 1;
				}
				if (bAggregate)
				{
					sb.Append(Environment.NewLine);
					sb.Append("		private double AggrGrid(DataView dv, string ColName, string AggrInst)" + Environment.NewLine);
					sb.Append("		{" + Environment.NewLine);
					sb.Append("			int dvCnt = dv.Count;" + Environment.NewLine);
                    sb.Append("			bool bFirst = true;" + Environment.NewLine);
                    //sb.Append("			if (GetAuthRow().Rows[0][\"AllowAdd\"].ToString() == \"Y\" && dvCnt > 0) {dvCnt = dvCnt - 1;}" + Environment.NewLine);
					sb.Append("			if (AggrInst == \"C\") {return dvCnt;}" + Environment.NewLine);
                    sb.Append("			else try" + Environment.NewLine);
					sb.Append("			{" + Environment.NewLine);
					sb.Append("				double tt = 0;" + Environment.NewLine);
                    sb.Append("				double vv = 0;" + Environment.NewLine);
                    sb.Append("				double mm = 0;" + Environment.NewLine);
                    sb.Append("				double ii = 0;" + Environment.NewLine);
                    sb.Append("				foreach (DataRowView drv in dv)" + Environment.NewLine);
					sb.Append("				{" + Environment.NewLine);
					sb.Append("					if (drv[ColName].ToString() != string.Empty)" + Environment.NewLine);
                    sb.Append("				    {" + Environment.NewLine);
                    sb.Append("				        vv = Double.Parse(drv[ColName].ToString());" + Environment.NewLine);
                    sb.Append("				        if (bFirst) { mm = vv; ii = vv; bFirst = false; }" + Environment.NewLine);
                    sb.Append("				        else" + Environment.NewLine);
                    sb.Append("				        {" + Environment.NewLine);
                    sb.Append("				            if (vv > mm) { mm = vv; }" + Environment.NewLine);
                    sb.Append("				            if (vv < ii) { ii = vv; }" + Environment.NewLine);
                    sb.Append("				        }" + Environment.NewLine);
                    sb.Append("				        tt = tt + vv;" + Environment.NewLine);
                    sb.Append("				    }" + Environment.NewLine);
                    sb.Append("				}" + Environment.NewLine);
                    sb.Append("				if (AggrInst == \"S\") {return tt;}" + Environment.NewLine);
                    sb.Append("				else if (AggrInst == \"M\") { return mm; }" + Environment.NewLine);
                    sb.Append("				else if (AggrInst == \"I\") { return ii; }" + Environment.NewLine);
                    sb.Append("				else if (AggrInst == \"A\" && dvCnt > 0) {return tt/dvCnt;} else {return 0;}" + Environment.NewLine);
                    sb.Append("			} catch { return 0; }" + Environment.NewLine);
					sb.Append("		}" + Environment.NewLine);
                    sb.Append("		protected string GetAggr(string columnName, string typ)" + Environment.NewLine);
                    sb.Append("		{" + Environment.NewLine);
                    sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                    sb.Append("			if (dt != null) return AggrGrid(dt.DefaultView, columnName, typ).ToString(\"F9\"); //to prevent scientific notation" + Environment.NewLine);
                    sb.Append("			else return string.Empty;" + Environment.NewLine);
                    sb.Append("		}" + Environment.NewLine);
                }
				sb.Append(Environment.NewLine);
                sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnItemEditing(object sender, ListViewEditEventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
                sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                sb.Append("			if ((ValidPage()) && UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\")) && dt != null && dt.DefaultView.Count > GetDataItemIndex(e.NewEditIndex))" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
                sb.Append("				c" + dw["ProgramName"].ToString() + "Grid.EditIndex = e.NewEditIndex;" + Environment.NewLine);
				sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_DataBind(null);" + Environment.NewLine);
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = "MasterTable = 'Y'"; }
				foreach (DataRowView drv in dv)
				{
                    if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                    {
						sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Script();" + Environment.NewLine);
					}
                    // Do not trigger event automatically for Button and ImageButton; Checkbox will be handled later.
					if (drv["ColPostBack"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",Calendar,TextBox,ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
						if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectedIndexChanged((object)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"), new EventArgs());" + Environment.NewLine);
						}
						else if (",Calendar,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
							sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectionChanged((object)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"), new EventArgs());" + Environment.NewLine);
						}
						else
						{
							sb.Append("				c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged((object)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"), new EventArgs());" + Environment.NewLine);
						}
					}
				}
                sb.Append("				Control wc = null;" + Environment.NewLine);
                sb.Append("				string idx = Page.Request[\"__EVENTARGUMENT\"];" + Environment.NewLine);
                sb.Append("				if (!string.IsNullOrEmpty(idx))" + Environment.NewLine);
                sb.Append("				{" + Environment.NewLine);
                sb.Append("				    Control ctrlToFocus = c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c\" + idx);" + Environment.NewLine);
                sb.Append("				    if (((WebControl)ctrlToFocus).Enabled) { wc = ctrlToFocus; }" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
                sb.Append("				if (wc == null) { wc = FindEditableControl(c" + dw["ProgramName"].ToString() + "Grid.EditItem); }" + Environment.NewLine);
                sb.Append("				if (wc != null)" + Environment.NewLine);
                sb.Append("             {" + Environment.NewLine);
                sb.Append("                 if (wc is RoboCoder.WebControls.ComboBox)" + Environment.NewLine);
                sb.Append("                 {" + Environment.NewLine);
                sb.Append("                     if (isMobile.Text != \"isMobile\") ScriptManager.GetCurrent(Parent.Page).SetFocus(((RoboCoder.WebControls.ComboBox)wc).FocusID);" + Environment.NewLine);
                sb.Append("                 }" + Environment.NewLine);
                sb.Append("                 else if (wc is CheckBox && (\"c\" + idx) == wc.ID)" + Environment.NewLine);
                sb.Append("                 {" + Environment.NewLine);
                sb.Append("                     ((CheckBox)wc).Checked = !((CheckBox)wc).Checked; ShowDirty(true);" + Environment.NewLine);
                foreach (DataRowView drv in dv)
                {
                    // trigger checkbox_checkedchanged event if defined
                    if (drv["ColPostBack"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        sb.Append("	    			    if (wc.ID == \"" + "c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\") c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_CheckedChanged(wc, new EventArgs());" + Environment.NewLine);
                    }
                }
                sb.Append("                 }" + Environment.NewLine);
                sb.Append("                 else" + Environment.NewLine);
                sb.Append("                 {" + Environment.NewLine);
                sb.Append("                     if (isMobile.Text != \"isMobile\") ScriptManager.GetCurrent(Parent.Page).SetFocus(wc.ClientID);" + Environment.NewLine);
                sb.Append("                 }" + Environment.NewLine);
                sb.Append("             }" + Environment.NewLine);
                sb.Append("             MkMobileLabel(c" + dw["ProgramName"].ToString() + "Grid.EditItem);" + Environment.NewLine);
                sb.Append("		    }" + Environment.NewLine);
                sb.Append("		    else { e.Cancel = true; }" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		private void MkMobileLabel(ListViewItem lvi)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                sb.Append("		    Label ml = null;" + Environment.NewLine);
                ii = 0;
                foreach (DataRowView drv in dv)
                {
                    sb.Append("		    ml = lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "ml\") as Label;" + Environment.NewLine);
                    sb.Append("		    if (ml != null) { ml.Text = ColumnHeaderText(" + (iOffset + ii).ToString() + "); }" + Environment.NewLine);
                    ii = ii + 1;
                }
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		protected void GridFill(ListViewItem lvi, DataTable dt, DataRow dr, bool bInsert)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                bool firstCb = true;
                bool firstCbb = true;
                bool firstDdl = true;
                bool firstLsb = true;
                bool firstRdb = true;
                bool firstTbc = true;
                bool firstIb = true;
                bool firstTb = true;
                bool firstDdlRef = true;
                bool firstEtb = true;
                ii = 0;
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = "MasterTable = 'Y'"; }
                foreach (DataRowView drv in dv)
                {
                    //if ((drv["ColumnIdentity"].ToString() != "Y" && drv["TableId"].ToString() != string.Empty && (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DdlRefColumnId"].ToString() == string.Empty || drv["DisplayMode"].ToString().ToLower() == "currency") && (drv["SystemValue"].ToString() == string.Empty || drv["DefAlways"].ToString() != "Y")) || drv["DisplayMode"].ToString().ToLower() == "document")
                    if ((drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DdlRefColumnId"].ToString() == string.Empty || drv["DisplayMode"].ToString().ToLower() == "currency") && (drv["SystemValue"].ToString() == string.Empty || drv["DefAlways"].ToString() != "Y")) || drv["DisplayMode"].ToString().ToLower() == "document")
                    {
                        if (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        {
                            string vv = string.Empty;
                            if (drv["DisplayName"].ToString() == "ComboBox")
                            {
                                vv = "cbb";
                                if (firstCbb) { sb.Append("			RoboCoder.WebControls.ComboBox cbb = null;" + Environment.NewLine); firstCbb = false; }
                            }
                            else if (drv["DisplayName"].ToString() == "DropDownList")
                            {
                                vv = "ddl";
                                if (firstDdl) { sb.Append("			" + drv["DisplayName"].ToString() + " ddl = null;" + Environment.NewLine); firstDdl = false; }
                            }
                            else if (drv["DisplayName"].ToString() == "ListBox")
                            {
                                vv = "lsb";
                                if (firstLsb) { sb.Append("			" + drv["DisplayName"].ToString() + " lsb = null;" + Environment.NewLine); firstLsb = false; }
                            }
                            else
                            {
                                vv = "rdb";
                                if (firstRdb) { sb.Append("			" + drv["DisplayName"].ToString() + " rdb = null;" + Environment.NewLine); firstRdb = false; }
                            }
                            sb.Append("			" + vv + " = (");
                            if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("TextBox"); }
                            else if (",ComboBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("RoboCoder.WebControls.ComboBox"); }
                            else { sb.Append(drv["DisplayName"].ToString()); }
                            sb.Append(")lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\");" + Environment.NewLine);
                            //sb.Append("			if (" + vv + " != null && " + vv + ".Visible)" + Environment.NewLine);
                            sb.Append("			if (" + vv + " != null)" + Environment.NewLine);
                            sb.Append("			{" + Environment.NewLine);
                            if (drv["DisplayName"].ToString() == "ComboBox")
                            {
                                sb.Append("				if (" + vv + ".SelectedValue != string.Empty)" + Environment.NewLine);
                                sb.Append("				{" + Environment.NewLine);
                                sb.Append("					dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = " + vv + ".SelectedValue;" + Environment.NewLine);
                                sb.Append("					dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"] = " + vv + ".SelectedText;" + Environment.NewLine);
                                sb.Append("				}" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("				if (" + vv + ".SelectedIndex >= 0 && " + vv + ".SelectedValue.ToString() != string.Empty)" + Environment.NewLine);
                                sb.Append("				{" + Environment.NewLine);
                                sb.Append("					dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = " + vv + ".SelectedValue;" + Environment.NewLine);
                                sb.Append("					dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"] = " + vv + ".SelectedItem.Text;" + Environment.NewLine);
                                sb.Append("				}" + Environment.NewLine);
                            }
                            sb.Append("				else" + Environment.NewLine);
                            sb.Append("				{" + Environment.NewLine);
                            sb.Append("					dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = System.DBNull.Value;" + Environment.NewLine);
                            sb.Append("					dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"] = System.DBNull.Value;" + Environment.NewLine);
                            sb.Append("				}" + Environment.NewLine);
                            foreach (DataRowView drvDdl in dv)
                            {
                                if (drvDdl["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drvDdl["DisplayName"].ToString() + ",") < 0 && drvDdl["DdlRefColumnId"].ToString() == drv["ScreenObjId"].ToString())
                                {
                                    if (firstDdlRef)
                                    {
                                        sb.Append("				DataTable dt = null;" + Environment.NewLine);
                                        firstDdlRef = false;
                                    }
                                    sb.Append("				dt = (DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "];" + Environment.NewLine);
                                    sb.Append("				foreach (DataRow dr in dt.Rows)" + Environment.NewLine);
                                    sb.Append("				{" + Environment.NewLine);
                                    sb.Append("					if (dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() == " + vv + ".SelectedItem.Value)" + Environment.NewLine);
                                    sb.Append("					{" + Environment.NewLine);
                                    sb.Append("						dr[\"" + drvDdl["ColumnName"].ToString() + drvDdl["TableId"].ToString() + "\"] = dr[\"" + drvDdl["ColumnName"].ToString() + drvDdl["TableId"].ToString() + "\"].ToString(); break;" + Environment.NewLine);
                                    sb.Append("					}" + Environment.NewLine);
                                    sb.Append("				}" + Environment.NewLine);
                                }
                            }
                            sb.Append("			}" + Environment.NewLine);
                        }
                        else if (drv["DisplayMode"].ToString().ToLower() == "currency")
                        {
                            if (firstTbc) { sb.Append("			TextBox tbc = null;" + Environment.NewLine); firstTbc = false; }
                            sb.Append("			tbc = (TextBox)lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\");" + Environment.NewLine);
                            //sb.Append("			if (tbc != null && tbc.Visible)" + Environment.NewLine);
                            sb.Append("			if (tbc != null)" + Environment.NewLine);
                            sb.Append("			{" + Environment.NewLine);
                            sb.Append("			    if (tbc.Text != string.Empty)" + Environment.NewLine);
                            sb.Append("			    {" + Environment.NewLine);
                            sb.Append("			        dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = Decimal.Parse(tbc.Text.Trim(), System.Globalization.NumberStyles.Currency, new System.Globalization.CultureInfo(");
                            if (string.IsNullOrEmpty(drv["DdlRefColumnName"].ToString())) { sb.Append("base.LUser.Culture"); }
                            else
                            {
                                if (",ComboBox,".IndexOf("," + drv["DdlRefDisplayName"].ToString() + ",") >= 0) { sb.Append("((RoboCoder.WebControls.ComboBox)"); } else { sb.Append("((" + drv["DdlRefDisplayName"].ToString() + ")"); }
                                sb.Append("lvi.FindControl(\"c" + drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString() + "\"))");
                                if (",ComboBox,DropDownList,RadioButtonList,".IndexOf("," + drv["DdlRefDisplayName"].ToString() + ",") >= 0) { sb.Append(".SelectedValue"); } else { sb.Append(".Text"); }
                            }
                            sb.Append(")).ToString();" + Environment.NewLine);
                            sb.Append("			    }" + Environment.NewLine);
                            sb.Append("			    else" + Environment.NewLine);
                            sb.Append("			    {" + Environment.NewLine);
                            sb.Append("			        dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = System.DBNull.Value;" + Environment.NewLine);
                            sb.Append("			    }" + Environment.NewLine);
                            sb.Append("			}" + Environment.NewLine);
                        }
                        else if (drv["DdlRefColumnId"].ToString() == string.Empty)
                        {
                            if (drv["DisplayName"].ToString() == "CheckBox")
                            {
                                if (firstCb)
                                {
                                    sb.Append("			CheckBox cb = null;" + Environment.NewLine);
                                    firstCb = false;
                                }
                                sb.Append("			cb = (CheckBox)lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\");" + Environment.NewLine);
                                //sb.Append("			if (cb != null && cb.Visible)" + Environment.NewLine);
                                sb.Append("			if (cb != null)" + Environment.NewLine);
                                sb.Append("			{" + Environment.NewLine);
                                sb.Append("				dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = base.SetBool(cb.Checked);" + Environment.NewLine);
                                sb.Append("			}" + Environment.NewLine);
                            }
                            else if (",EncryptedTextBox,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                            {
                                if (firstEtb)
                                {
                                    sb.Append("			RoboCoder.WebControls.EncryptedTextBox etb = null;" + Environment.NewLine);
                                    firstEtb = false;
                                }
                                sb.Append("			etb = (RoboCoder.WebControls.EncryptedTextBox)lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\");" + Environment.NewLine);
                                //sb.Append("			if (etb != null && etb.Visible)" + Environment.NewLine);
                                sb.Append("			if (etb != null)" + Environment.NewLine);
                                sb.Append("			{" + Environment.NewLine);
                                sb.Append("				if (etb.Text != string.Empty) {dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = " + "etb.EncryptedText" + ";} else {dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = System.DBNull.Value;}" + Environment.NewLine);
                                sb.Append("			}" + Environment.NewLine);
                            }
                            else if (",TextBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 && drv["DataTypeSqlName"].ToString().ToLower() != "varbinary")
                            {
                                if (firstTb)
                                {
                                    sb.Append("			TextBox tb = null;" + Environment.NewLine);
                                    firstTb = false;
                                }
                                sb.Append("			tb = (TextBox)lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\");" + Environment.NewLine);
                                //sb.Append("			if (tb != null && tb.Visible)" + Environment.NewLine);
                                sb.Append("			if (tb != null)" + Environment.NewLine);
                                sb.Append("			{" + Environment.NewLine);
                                sb.Append("				if (tb.Text != string.Empty) {dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = " + (drv["DisplayMode"].ToString().Contains("Date") ? "base.ToIntDateTime(tb.Text," + (drv["DisplayMode"].ToString().Contains("UTC") ? "true" : "false") + ",false)" : "tb.Text") + ";} else {dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = System.DBNull.Value;}" + Environment.NewLine);
                                sb.Append("			}" + Environment.NewLine);
                            }
                        }
                    }
                    ii = ii + 1;
                }
                foreach (DataRowView drv in dv)
                {
                    if (drv["DisplayName"].ToString().ToLower() == "imagebutton" && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                    {
                        string keyContentColumnName = drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString();
                        keyContentColumnName = !string.IsNullOrEmpty(keyContentColumnName) ? keyContentColumnName : (drv["MasterTable"].ToString() == "Y" ? pMKeyColumn : pDKeyColumn);
                        string pKeyColumnName = drv["ColTblPK"].ToString();
                        pKeyColumnName = !string.IsNullOrEmpty(pKeyColumnName) ? pKeyColumnName : (drv["MasterTable"].ToString() == "Y" ? pMKey : pDKey);
                        string pKeyDbAppDatabase = (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".");
                        string pKeySystemId = drv["SystemId"].ToString();

                        if (firstIb) { sb.Append("		    DataTable dtImg = null;" + Environment.NewLine); firstIb = false; }
                        sb.Append("		    if (!string.IsNullOrEmpty(dr[\"" + (drv["MasterTable"].ToString() == "Y" ? pMKeyColumn : pDKeyColumn) + "\"].ToString()))" + Environment.NewLine);
                        sb.Append("		    {" + Environment.NewLine);
                        sb.Append("		        if (lvi.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\") != null)" + Environment.NewLine);
                        sb.Append("		        {" + Environment.NewLine);
                        sb.Append("		            dtImg = (new AdminSystem()).GetDbImg(dr[\"" + keyContentColumnName + "\"].ToString(), \"" + pKeyDbAppDatabase + "dbo." + drv["TableName"].ToString() + "\", \"" + pKeyColumnName + "\", \"" + drv["ColumnName"].ToString() + "\", LcAppConnString, LcAppPw);" + Environment.NewLine);
                        sb.Append("		            if (dtImg != null && dtImg.Rows.Count > 0)" + Environment.NewLine);
                        sb.Append("		            {" + Environment.NewLine);
                        sb.Append("		                dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = dtImg.Rows[0][0] as byte[];" + Environment.NewLine);
                        sb.Append("		            }" + Environment.NewLine);
                        sb.Append("		        }" + Environment.NewLine);
                        sb.Append("		    }" + Environment.NewLine);
                    }
                }
                sb.Append("		    if (bInsert) { dt.Rows.InsertAt(dr, 0); }" + Environment.NewLine);
                sb.Append("			Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dt;" + Environment.NewLine);
                sb.Append("			c" + dw["ProgramName"].ToString() + "Grid.EditIndex = -1;" + Environment.NewLine);
                sb.Append("			c" + dw["ProgramName"].ToString() + "Grid_DataBind(dt.DefaultView);" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnItemUpdating(object sender, ListViewUpdateEventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                sb.Append("			if (dt != null && dt.Rows.Count > 0)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
                sb.Append("				DataRow dr = dt.DefaultView[GetDataItemIndex(e.ItemIndex)].Row;" + Environment.NewLine);
                sb.Append("			    GridFill(c" + dw["ProgramName"].ToString() + "Grid.EditItem, dt, dr, false);" + Environment.NewLine);
                sb.Append("			    dr[\"_NewRow\"] = \"N\";" + Environment.NewLine);
                sb.Append("			    if (dt.Columns.Contains(\"_SortOrder\")) dr[\"_SortOrder\"] = null;" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnItemCanceling(object sender, ListViewCancelEventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
                sb.Append("			PanelTop.Update();" + Environment.NewLine);
                sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
                sb.Append("			DataView dv = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
                sb.Append("			if (dv != null && dv[GetDataItemIndex(e.ItemIndex)][\"_NewRow\"].ToString() == \"Y\")" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
                sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_OnItemDeleting(sender, new ListViewDeleteEventArgs(e.ItemIndex));" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
                sb.Append("			if (dt.Columns.Contains(\"_SortOrder\")) dt.DefaultView[GetDataItemIndex(e.ItemIndex)].Row[\"_SortOrder\"] = null;" + Environment.NewLine);
                firstIb = true;
                foreach (DataRowView drv in dv)
                {
                    if (drv["DisplayName"].ToString().ToLower() == "imagebutton" && drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                    {
                        string keyContentColumnName = drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString();
                        keyContentColumnName = !string.IsNullOrEmpty(keyContentColumnName) ? keyContentColumnName : (drv["MasterTable"].ToString() == "Y" ? pMKeyColumn : pDKeyColumn);
                        string pKeyColumnName = drv["ColTblPK"].ToString();
                        pKeyColumnName = !string.IsNullOrEmpty(pKeyColumnName) ? pKeyColumnName : (drv["MasterTable"].ToString() == "Y" ? pMKey : pDKey);
                        string pKeyDbAppDatabase = (CSrc.SrcSystemId.ToString() == drv["SystemId"].ToString() ? string.Empty : drv["dbAppDatabase"].ToString() + ".");
                        string pKeySystemId = drv["SystemId"].ToString();

                        if (firstIb) { sb.Append("			DataTable dtImg = null;" + Environment.NewLine); firstIb = false; }
                        sb.Append("			dtImg = (new AdminSystem()).GetDbImg(dv.Count == 0 ? \"0\" : dv[GetDataItemIndex(e.ItemIndex)].Row[\"" + keyContentColumnName + "\"].ToString(), \"" + pKeyDbAppDatabase + "dbo." + drv["TableName"].ToString() + "\", \"" + pKeyColumnName + "\", \"" + drv["ColumnName"].ToString() + "\", LcAppConnString, LcAppPw);" + Environment.NewLine);
                        sb.Append("			if (dtImg != null && dtImg.Rows.Count > 0)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("			    dv[GetDataItemIndex(e.ItemIndex)].Row[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = dtImg.Rows[0][0] as byte[];" + Environment.NewLine);
                        sb.Append("			}" + Environment.NewLine);
                    }
                }
                sb.Append("			c" + dw["ProgramName"].ToString() + "Grid.EditIndex = -1; c" + dw["ProgramName"].ToString() + "Grid_DataBind(null);" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		protected void cDeleteAllButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
				sb.Append("			DataView dv = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
                sb.Append("			if (dv != null && (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || UpdateGridRow(sender, new CommandEventArgs(\"Save\", \"\"))))" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				sb.Append("				GotoPage(0);" + Environment.NewLine);
				sb.Append("				while (dv.Count > 0) {dv.Delete(0);}" + Environment.NewLine);
                //sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_AddNew(dt);" + Environment.NewLine);
				sb.Append("				Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dt;" + Environment.NewLine);
                sb.Append("				c" + dw["ProgramName"].ToString() + "Grid.EditIndex = -1; c" + dw["ProgramName"].ToString() + "Grid_DataBind(dv);" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
                sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnItemDeleting(object sender, ListViewDeleteEventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "DELROR")
					{
						bWebRule = true;
						sb.Append("				//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("				// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					sb.Append("			DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
					sb.Append("			DataView dv = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
                    sb.Append("			DataRow dr = dv != null ? dv[GetDataItemIndex(e.ItemIndex)].Row : null;" + Environment.NewLine);
                    sb.Append("			if (dv != null && (c" + dw["ProgramName"].ToString() + "Grid.EditIndex == e.ItemIndex || UpdateGridRow(sender, new CommandEventArgs(\"Save\",\"\"))))" + Environment.NewLine);
					sb.Append("			{" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "DELROG")
						{
							bWebRule = true;
							sb.Append("				//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("				// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("				// *** Delete Grid Row (before) Web Rule End *** //" + Environment.NewLine); }
                    //sb.Append("				int iBefDel = dv.Count;" + Environment.NewLine);
                    sb.Append("				dr.Delete();" + Environment.NewLine);
                    //sb.Append("				if (dv.Count == 0 && iBefDel == 2) {c" + dw["ProgramName"].ToString() + "Grid_AddNew(dt);}" + Environment.NewLine);
					sb.Append("				Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid] = dt;" + Environment.NewLine);
					sb.Append("				c" + dw["ProgramName"].ToString() + "Grid.EditIndex = -1; c" + dw["ProgramName"].ToString() + "Grid_DataBind(dv);" + Environment.NewLine);
					sb.Append("			}" + Environment.NewLine);
				}
				sb.Append("		}" + Environment.NewLine);
			}	// End of I2,I3
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append(Environment.NewLine);
				sb.Append("		public void cNewSaveButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "NewSave")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "NewSave")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			try {" + Environment.NewLine);
                    sb.Append("			    string msg = SaveDb(sender, new EventArgs());" + Environment.NewLine);
                    sb.Append("			    cNewButton_Click(sender, new EventArgs());" + Environment.NewLine);
                    sb.Append("			    if (msg != string.Empty && Config.PromptMsg) { bInfoNow.Value = \"Y\"; PreMsgPopup(msg); }" + Environment.NewLine);
                    sb.Append("			}" + Environment.NewLine);
                    sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                    bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "NewSave")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
                }
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cNewButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "New")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "New")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.ClearSearch(); Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List);" + Environment.NewLine);
                    sb.Append("			Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, null);" + Environment.NewLine);
                    //sb.Append("			// In the case of one item and being selected by default." + Environment.NewLine);
                    //sb.Append("			if (c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.Items.Count > 0 && !c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.Items[0].Selected)" + Environment.NewLine);
                    //sb.Append("			{" + Environment.NewLine);
                    //sb.Append("				c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedItem.Selected = false; c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.Items[0].Selected = true; c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectByValue(string.Empty,string.Empty,false); c" + dw["ProgramName"].ToString() + screenId.ToString() + "List_SelectedIndexChanged(sender, e);" + Environment.NewLine);
                    //sb.Append("			}" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "New")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
                }
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cClearButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Clear")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Clear")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			ClearMaster(sender, e);" + Environment.NewLine);
					if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append("			cDeleteAllButton_Click(sender, new EventArgs());" + Environment.NewLine); }
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Clear")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
                }
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cCopyButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Copy")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Copy")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			c" + pMKeyColumn + ".Text = string.Empty;" + Environment.NewLine);
					sb.Append("			c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.ClearSearch(); Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List);" + Environment.NewLine);
					sb.Append("			ShowDirty(true);" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Copy")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
                }
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		public void cCopySaveButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "CopySave")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "CopySave")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			try {" + Environment.NewLine);
                    sb.Append("			    string msg = SaveDb(sender, new EventArgs());" + Environment.NewLine);
                    sb.Append("			    cCopyButton_Click(sender, new EventArgs());" + Environment.NewLine);
                    sb.Append("			    if (msg != string.Empty && Config.PromptMsg) { bInfoNow.Value = \"Y\"; PreMsgPopup(msg); }" + Environment.NewLine);
                    sb.Append("			}" + Environment.NewLine);
                    sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                    bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "CopySave")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
                }
				sb.Append("		}" + Environment.NewLine);
			}
			sb.Append(Environment.NewLine);
			sb.Append("		public void cUndoAllButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			bWebRule = false;
			foreach (DataRowView drvr in dvWRule)
			{
				if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "UndoAll")
				{
					bWebRule = true;
					sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
					sb.Append(WrapConditionalWebRule("   ", drvr));
				}
			}
			if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
			else
			{
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "UndoAll")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
                    sb.Append("			if (c" + pMKeyColumn + ".Text == string.Empty) { cClearButton_Click(sender, new EventArgs()); ShowDirty(false); PanelTop.Update();}" + Environment.NewLine);
                    sb.Append("			else { Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, c" + pMKeyColumn + ".Text); }" + Environment.NewLine);
				}
				else
				{
					sb.Append("			Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, null);" + Environment.NewLine);
				}
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "UndoAll")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
            }
			sb.Append("		}" + Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append("		public void cPreviewButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            bWebRule = false;
            foreach (DataRowView drvr in dvWRule)
            {
                if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Preview")
                {
                    bWebRule = true;
                    sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append(WrapConditionalWebRule("   ", drvr));
                }
            }
            if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
            else
            {
                bWebRule = false;
                foreach (DataRowView drvr in dvWRule)
                {
                    if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Preview")
                    {
                        bWebRule = true;
                        sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                        sb.Append(WrapConditionalWebRule("   ", drvr));
                    }
                }
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                bWebRule = false;
                foreach (DataRowView drvr in dvWRule)
                {
                    if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Preview")
                    {
                        bWebRule = true;
                        sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                        sb.Append(WrapConditionalWebRule("   ", drvr));
                    }
                }
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
            }
            sb.Append("		}" + Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append("		public void cEditButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            bWebRule = false;
            foreach (DataRowView drvr in dvWRule)
            {
                if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Edit")
                {
                    bWebRule = true;
                    sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append(WrapConditionalWebRule("   ", drvr));
                }
            }
            if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
            else
            {
                bWebRule = false;
                foreach (DataRowView drvr in dvWRule)
                {
                    if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Edit")
                    {
                        bWebRule = true;
                        sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                        sb.Append(WrapConditionalWebRule("   ", drvr));
                    }
                }
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append("			cScreenSearch.Visible = true;" + Environment.NewLine); }
                if (dw["SysProgram"].ToString() == "Y") { sb.Append("			cSystem.Visible = true;" + Environment.NewLine); }
                sb.Append("			bUseCri.Value = \"Y\"; GetCriteria(GetScrCriteria());" + Environment.NewLine);
                if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                {
                    sb.Append("			Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List);");
                }
                else
                {
                    sb.Append("			Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + "Grid);");
                }
                sb.Append(" Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, null);" + Environment.NewLine);
                sb.Append("			cEditButton.Visible = false;" + Environment.NewLine);
                bWebRule = false;
                foreach (DataRowView drvr in dvWRule)
                {
                    if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Edit")
                    {
                        bWebRule = true;
                        sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                        sb.Append(WrapConditionalWebRule("   ", drvr));
                    }
                }
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
            }
            sb.Append("		}" + Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append("		public void cSaveCloseButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            bWebRule = false;
            foreach (DataRowView drvr in dvWRule)
            {
                if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "SaveClose")
                {
                    bWebRule = true;
                    sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                    sb.Append(WrapConditionalWebRule("   ", drvr));
                }
            }
            if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
            else
            {
                bWebRule = false;
                foreach (DataRowView drvr in dvWRule)
                {
                    if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "SaveClose")
                    {
                        bWebRule = true;
                        sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                        sb.Append(WrapConditionalWebRule("   ", drvr));
                    }
                }
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                sb.Append("			try {" + Environment.NewLine);
                sb.Append("			    string msg = SaveDb(sender, new EventArgs());" + Environment.NewLine);
                sb.Append("			    if (msg != string.Empty)" + Environment.NewLine);
                sb.Append("			    {" + Environment.NewLine);
                sb.Append("			        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), \"closeDlg\", @\"<script type='text/javascript'>window.parent.closeParentDlg();</script>\", false);" + Environment.NewLine);
                sb.Append("			    }" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
                sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
                bWebRule = false;
                foreach (DataRowView drvr in dvWRule)
                {
                    if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "SaveClose")
                    {
                        bWebRule = true;
                        sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
                        sb.Append(WrapConditionalWebRule("   ", drvr));
                    }
                }
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
            }
            sb.Append("		}" + Environment.NewLine);
            string sDeferError = dw["DeferError"].ToString() == "Y" ? "true" : "false";
            sb.Append(Environment.NewLine);
			sb.Append("		private string SaveDb(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
            sb.Append("			string rtn = string.Empty;" + Environment.NewLine);
            sb.Append("			bool noTrans = Config.NoTrans;" + Environment.NewLine);
            sb.Append("			int commandTimeOut = Config.CommandTimeOut;" + Environment.NewLine);
            bWebRule = false;
			foreach (DataRowView drvr in dvWRule)
			{
				if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Save")
				{
					bWebRule = true;
					sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
					sb.Append(WrapConditionalWebRule("   ", drvr));
				}
			}
			if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
			else
			{
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Save")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                sEvent = string.Empty;
				if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
                    sb.Append("			string pid = string.Empty;" + Environment.NewLine); // Do this here so the after-rule can identify the add-event.
                    dv.RowFilter = "MasterTable = 'Y'";
					foreach (DataRowView drv in dv)
					{
						if (drv["PwdOvride"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
						{
							sb.Append("			if (c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd.Visible) {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd_TextChanged(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd,new EventArgs());}" + Environment.NewLine);
							sEvent = sEvent + " && !c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd.Visible";
						}
					}
				}
				if ("I1".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					sb.Append("			if (ValidPage()" + sEvent + ")" + Environment.NewLine);
				}
				else if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
                    sb.Append("			if (ValidPage()" + sEvent + " && (c" + dw["ProgramName"].ToString() + "Grid.EditIndex < 0 || UpdateGridRow(c" + dw["ProgramName"].ToString() + "Grid, new CommandEventArgs(\"Save\", \"\"))))" + Environment.NewLine);
				}
				else
				{
					sb.Append("			if (ValidPage() && UpdateGridRow(c" + dw["ProgramName"].ToString() + "Grid, new CommandEventArgs(\"Save\", \"\")))" + Environment.NewLine);
				}
				sb.Append("			{" + Environment.NewLine);
                if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					sb.Append("				DataTable dt = (DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid];" + Environment.NewLine);
					sb.Append("				DataView dv = dt != null ? dt.DefaultView : null;" + Environment.NewLine);
					sb.Append("				string ftr = string.Empty;" + Environment.NewLine);
                    sb.Append("				if (dv.RowFilter != string.Empty) { ftr = dv.RowFilter; dv.RowFilter = string.Empty; }" + Environment.NewLine);
                    if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
					{
						sb.Append("				" + dw["ProgramName"].ToString() + screenId.ToString() + " ds = Prep" + dw["ProgramName"].ToString() + "Data(dv,c" + pMKeyColumn + ".Text == string.Empty);" + Environment.NewLine);
					}
					else
					{
						sb.Append("				" + dw["ProgramName"].ToString() + screenId.ToString() + " ds = Prep" + dw["ProgramName"].ToString() + "Data(dv,false);" + Environment.NewLine);
					}
					sb.Append("				if (ftr != string.Empty) {dv.RowFilter = ftr;}" + Environment.NewLine);
				}
				else // I1:
				{
					sb.Append("				" + dw["ProgramName"].ToString() + screenId.ToString() + " ds = Prep" + dw["ProgramName"].ToString() + "Data(null,c" + pMKeyColumn + ".Text == string.Empty);" + Environment.NewLine);
				}
				if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
                    sb.Append("				if (!string.IsNullOrEmpty(c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue) && c" + pMKeyColumn + ".Text != c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue)" + Environment.NewLine);
                    sb.Append("				{" + Environment.NewLine);
                    sb.Append("					PreMsgPopup(\"Primary key cannot be changed\");" + Environment.NewLine);
                    sb.Append("					return rtn;" + Environment.NewLine);
                    sb.Append("				}" + Environment.NewLine);
                    // pMKeyColumn may not empty for non-identity primary key:
                    sb.Append("				if (string.IsNullOrEmpty(c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue))	// Add" + Environment.NewLine);
					sb.Append("				{" + Environment.NewLine);
					sb.Append("					if (ds != null)" + Environment.NewLine);
					sb.Append("					{" + Environment.NewLine);
                    sb.Append("						pid = (new AdminSystem()).AddData(" + screenId.ToString() + "," + sDeferError + ",base.LUser,base.LImpr,base.LCurr,ds" + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",base.CPrj,base.CSrc,noTrans,commandTimeOut);" + Environment.NewLine);
					sb.Append("					}" + Environment.NewLine);
                    sb.Append("					if (!string.IsNullOrEmpty(pid))" + Environment.NewLine);
					sb.Append("					{" + Environment.NewLine);
					dv.RowFilter = string.Empty;
					foreach (DataRowView drv in dv)
					{
                        if (drv["ColumnIdentity"].ToString() != "Y" && ",Document,DropDownList,ListBox,RadioButtonList,DataGridLink,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 && drv["RefreshOnCUD"].ToString() == "Y")
                        {
							sb.Append("						Session.Remove(KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ");" + Environment.NewLine);
						}
					}
					sb.Append("						c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.ClearSearch(); Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List);" + Environment.NewLine);
                    sb.Append("						ShowDirty(false); bUseCri.Value = \"Y\"; Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, pid);" + Environment.NewLine);
                    sb.Append("						rtn = GetScreenHlp().Rows[0][\"AddMsg\"].ToString();" + Environment.NewLine);
					sb.Append("					}" + Environment.NewLine);
					sb.Append("				}" + Environment.NewLine);
					sb.Append("				else {" + Environment.NewLine);
				}
				sb.Append("					bool bValid7 = false;" + Environment.NewLine);
                sb.Append("					if (ds != null && (new AdminSystem()).UpdData(" + screenId.ToString() + "," + sDeferError + ",base.LUser,base.LImpr,base.LCurr,ds" + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",base.CPrj,base.CSrc,noTrans,commandTimeOut)) {bValid7 = true;}" + Environment.NewLine);
				sb.Append("					if (bValid7)" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				dv.RowFilter = string.Empty;
				foreach (DataRowView drv in dv)
				{
                    if (drv["ColumnIdentity"].ToString() != "Y" && ",Document,DropDownList,ListBox,RadioButtonList,DataGridLink,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 && drv["RefreshOnCUD"].ToString() == "Y")
                    {
						sb.Append("						Session.Remove(KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ");" + Environment.NewLine);
					}
				}
				if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					sb.Append("						c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.ClearSearch(); Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List);" + Environment.NewLine);
				}
				if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
                    sb.Append("						Session[KEY_currPageIndex] = GetCurrPageIndex();" + Environment.NewLine);
				}
				if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					sb.Append("						ShowDirty(false); Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].Rows[0][\"" + pMKeyColumn + "\"]);" + Environment.NewLine);
				}
				else
				{
                    sb.Append("						ShowDirty(false); bUseCri.Value = \"Y\"; Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, null);" + Environment.NewLine);
				}
                sb.Append("						rtn = GetScreenHlp().Rows[0][\"UpdMsg\"].ToString();" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
                if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append("				}" + Environment.NewLine); }
				sb.Append("			}" + Environment.NewLine);
                bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Save")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
                if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
            }
            sb.Append("			return rtn;" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append("		public void cSaveButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("			try {" + Environment.NewLine);
            sb.Append("			    string msg = SaveDb(sender, e);" + Environment.NewLine);
            sb.Append("			    if (msg != string.Empty && Config.PromptMsg) { bInfoNow.Value = \"Y\"; PreMsgPopup(msg); }" + Environment.NewLine);
            sb.Append("			}" + Environment.NewLine);
            sb.Append("			catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append(Environment.NewLine);
				sb.Append("		public void cDeleteButton_Click(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				bWebRule = false;
				foreach (DataRowView drvr in dvWRule)
				{
					if (drvr["EventCode"].ToString() == "BUTCLR" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Delete")
					{
						bWebRule = true;
						sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
						sb.Append(WrapConditionalWebRule("   ", drvr));
					}
				}
				if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); }
				else
				{
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLK" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Delete")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (Before) Web Rule starts here *** //" + Environment.NewLine); }
                    sb.Append("			if (c" + pMKeyColumn + ".Text != string.Empty)" + Environment.NewLine);
					sb.Append("			{" + Environment.NewLine);
					sb.Append("				" + dw["ProgramName"].ToString() + screenId.ToString() + " ds = Prep" + dw["ProgramName"].ToString() + "Data(null,false);" + Environment.NewLine);
					sb.Append("				try" + Environment.NewLine);
					sb.Append("				{" + Environment.NewLine);
                    sb.Append("					if (ds != null && (new AdminSystem()).DelData(" + screenId.ToString() + "," + sDeferError + ",base.LUser,base.LImpr,base.LCurr,ds" + Robot.GetCnStr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",base.CPrj,base.CSrc))" + Environment.NewLine);
					sb.Append("					{" + Environment.NewLine);
					dv.RowFilter = string.Empty;
					foreach (DataRowView drv in dv)
					{
                        if (drv["ColumnIdentity"].ToString() != "Y" && ",Document,DropDownList,ListBox,RadioButtonList,DataGridLink,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0 && drv["RefreshOnCUD"].ToString() == "Y")
                        {
							sb.Append("						Session.Remove(KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ");" + Environment.NewLine);
						}
					}
					sb.Append("						c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.ClearSearch(); Session.Remove(KEY_dt" + dw["ProgramName"].ToString() + screenId.ToString() + "List);" + Environment.NewLine);
					sb.Append("						ShowDirty(false); Pop" + dw["ProgramName"].ToString() + screenId.ToString() + "List(sender, e, false, null);" + Environment.NewLine);
                    sb.Append("						if (Config.PromptMsg) {bInfoNow.Value = \"Y\"; PreMsgPopup(GetScreenHlp().Rows[0][\"DelMsg\"].ToString());}" + Environment.NewLine);
					sb.Append("					}" + Environment.NewLine);
					sb.Append("				}" + Environment.NewLine);
                    sb.Append("				catch (Exception err) { bErrNow.Value = \"Y\"; PreMsgPopup(err.Message); return; }" + Environment.NewLine);
					sb.Append("			}" + Environment.NewLine);
					bWebRule = false;
					foreach (DataRowView drvr in dvWRule)
					{
						if (drvr["EventCode"].ToString() == "BUTCLA" && drvr["ObjectType"].ToString() == "S" && drvr["ButtonTypeName"].ToString() == "Delete")
						{
							bWebRule = true;
							sb.Append("			//WebRule: " + drvr["RuleName"].ToString() + Environment.NewLine);
							sb.Append(WrapConditionalWebRule("   ", drvr));
						}
					}
                    if (bWebRule) { sb.Append("			// *** WebRule End *** //" + Environment.NewLine); } else { sb.Append("			// *** System Button Click (After) Web Rule starts here *** //" + Environment.NewLine); }
                }
				sb.Append("		}" + Environment.NewLine);
            }
            sb.Append(Environment.NewLine);
			sb.Append("		private " + dw["ProgramName"].ToString() + screenId.ToString() + " Prep" + dw["ProgramName"].ToString() + "Data(DataView dv, bool bAdd)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			" + dw["ProgramName"].ToString() + screenId.ToString() + " ds = new " + dw["ProgramName"].ToString() + screenId.ToString() + "();" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("			DataRow dr = ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].NewRow();" + Environment.NewLine);
                sb.Append("			DataRow drType = ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].NewRow();" + Environment.NewLine);
                sb.Append("			DataRow drDisp = ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].NewRow();" + Environment.NewLine);
                if (pMKeyIdentity == "Y")
				{
                    sb.Append("			if (bAdd) { dr[\"" + pMKeyColumn + "\"] = string.Empty; } else { dr[\"" + pMKeyColumn + "\"] = c" + pMKeyColumn + ".Text; }" + Environment.NewLine);
				}
				else
				{
                    sb.Append("			dr[\"" + pMKeyColumn + "\"] = c" + pMKeyColumn + ".Text;" + Environment.NewLine);
				}
                sb.Append("			drType[\"" + pMKeyColumn + "\"] = \"" + pMKeyDByteOle + "\"; drDisp[\"" + pMKeyColumn + "\"] = \"" + pMKeyDisplay + "\";" + Environment.NewLine);
                dv.RowFilter = "MasterTable = 'Y'";
                bool bHasType;
				foreach (DataRowView drv in dv)
				{
                    bHasType = false;
                    if (drv["ColumnIdentity"].ToString() != "Y" && (",Button,ImageButton,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString())))
					{
                        if (drv["DisplayName"].ToString() == "ListBox")
						{
                            if (drv["DisplayMode"].ToString() == "AutoListBox") sb.Append("			Set" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "," + "c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Hidden.Text" + ");" + Environment.NewLine);
                            sb.Append("			foreach (ListItem li in c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Items)" + Environment.NewLine);
                            sb.Append("			{" + Environment.NewLine);
							sb.Append("				if (li.Selected && li.Value != string.Empty)" + Environment.NewLine);
							sb.Append("				{" + Environment.NewLine);
							sb.Append("					if (dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() != string.Empty) { dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() + \",\"; }" + Environment.NewLine);
							if (drv["DdlKeyNumeric"].ToString() == "Y")
							{
								sb.Append("					dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() + li.Value; " + Environment.NewLine);
							}
							else
							{
								sb.Append("					dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() + \"'\" + li.Value.Replace(\"'\",\"''\") + \"'\"; " + Environment.NewLine);
							}
							sb.Append("				}" + Environment.NewLine);
							sb.Append("			}" + Environment.NewLine);
                            if (drv["DefAlways"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                            {
                                sb.Append("			dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = \"(");
                                sb.Append(drv["DefaultValue"].ToString());
                                sb.Append(")\";" + Environment.NewLine);
                            }
                            else if (drv["DefAfter"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                            {
                                sb.Append("			if (dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() == string.Empty && bAdd) { dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = \"(");
                                sb.Append(drv["DefaultValue"].ToString());
                                sb.Append(")\";}" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("			if (dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() != string.Empty) { dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = \"(\" + dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() + \")\"; }" + Environment.NewLine);
                            }
                            bHasType = true;
                        }
						else if (",ComboBox,DropDownList,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
						{
                            if (drv["DefAlways"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                            {
                                sb.Append("			try {dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = ");
                                sb.Append(Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + ";} catch {};" + Environment.NewLine);
                            }
                            else if (drv["DefAfter"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                            {
                                sb.Append("			try { dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = ");
                                sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedValue == string.Empty && bAdd ");
                                sb.Append("? " + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + ".ToString()");
                                sb.Append(": c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedValue");
                                sb.Append(";} catch {};" + Environment.NewLine);
                            }
                            else
                            {
                                sb.Append("			try {dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedValue;} catch {}" + Environment.NewLine);
                            }
                            bHasType = true;
                        }
                        else if (drv["DisplayMode"].ToString().ToLower() == "document")
                        {
                            sb.Append("			try {dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = string.Empty;} catch {}" + Environment.NewLine);
                            bHasType = true;
                        }
                        else if (drv["DisplayName"].ToString() == "ImageButton")
                        {
                            if (drv["DataTypeSqlName"].ToString().ToLower() != "varbinary")
                            {
                                sb.Append("			try {dr[\"" + drv["ColName"].ToString() + drv["TableId"].ToString() + "\"] = Utils.StripTilde(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Div.Text, true);} catch {}" + Environment.NewLine);
                                bHasType = true;
                            }
                        }
                        else if ((drv["DdlRefColumnId"].ToString() == string.Empty || drv["DisplayMode"].ToString().ToLower() == "currency") && (drv["SystemValue"].ToString() == string.Empty || drv["DefAlways"].ToString() != "Y"))
                        {
                            sb.Append("			try {dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = ");
                            if (drv["DisplayMode"].ToString().Contains("DateTime"))
                            {
                                sb.Append("base.ToIntDateTime(");
                                if (drv["DefAlways"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                                {
                                    sb.Append(Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()));
                                }
                                else if (drv["DefAfter"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                                {
                                    sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text == string.Empty && bAdd ");
                                    sb.Append("? " + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + ".ToString()");
                                    sb.Append(": c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text");
                                }
                                else
                                {
                                    sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text");
                                }
                                sb.Append(",");
                                sb.Append(drv["DisplayMode"].ToString().Contains("UTC") ? "true" : "false");
                                sb.Append(",true);");
                            }
                            else
                            {
                                switch (drv["DisplayName"].ToString())
                                {
                                    case "CheckBox":
                                        sb.Append("base.SetBool(");
                                        sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Checked");
                                        sb.Append(");");
                                        break;
                                    case "Calendar":
                                        if (drv["DefAlways"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                                        {
                                            sb.Append(Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()));
                                        }
                                        else if (drv["DefAfter"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                                        {
                                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedDate == string.Empty && bAdd ");
                                            sb.Append("? " + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + ".ToString()");
                                            sb.Append(": c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedDate");
                                        }
                                        else
                                        {
                                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SelectedDate");
                                        }
                                        sb.Append(";");
                                        break;
                                    case "Editor":
                                        if (drv["DefAlways"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                                        {
                                            sb.Append(Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()));
                                        }
                                        else if (drv["DefAfter"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                                        {
                                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Content == string.Empty && bAdd ");
                                            sb.Append("? " + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + ".ToString()");
                                            sb.Append(": c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Content");
                                        }
                                        else
                                        {
                                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Content");
                                        }
                                        sb.Append(";");
                                        break;
                                    default:
                                        if (drv["DefAlways"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                                        {
                                            sb.Append(Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()));
                                        }
                                        else if (drv["DefAfter"].ToString() == "Y" && drv["DefaultValue"].ToString() != string.Empty)
                                        {
                                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text == string.Empty && bAdd ");
                                            sb.Append("? " + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + ".ToString()");
                                            sb.Append(": c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text");
                                        }
                                        else if (drv["DisplayMode"].ToString().ToLower() == "currency")
                                        {
                                            sb.Append("Decimal.Parse(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text.Trim(), System.Globalization.NumberStyles.Currency, new System.Globalization.CultureInfo(");
                                            if (string.IsNullOrEmpty(drv["DdlRefColumnName"].ToString())) { sb.Append("base.LUser.Culture"); }
                                            else
                                            {
                                                sb.Append("c" + drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString());
                                                if (",ComboBox,DropDownList,RadioButtonList,".IndexOf("," + drv["DdlRefDisplayName"].ToString() + ",") >= 0) { sb.Append(".SelectedValue"); } else { sb.Append(".Text"); }
                                            }
                                            sb.Append(")).ToString()");
                                        }
                                        else if (drv["DisplayName"].ToString().ToLower() == "signature")
                                        {
                                            sb.Append("Convert.ToBase64String(c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".SignatureData)");
                                        }
                                        else if (drv["DisplayMode"].ToString() == "EncryptedTextBox")
                                        {
                                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".EncryptedText");
                                        }
                                        else
                                        {
                                            sb.Append("c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Text");
                                            if (drv["TrimOnEntry"].ToString() == "Y" && drv["DisplayMode"].ToString() == "TextBox") { sb.Append(".Trim()"); }
                                        }
                                        sb.Append(";");
                                        break;
                                }
                            }
                            sb.Append("} catch {}" + Environment.NewLine);
                            bHasType = true;
                        }
                        if (bHasType)
                        {
                            if (string.IsNullOrEmpty(drv["TableId"].ToString()))    // Just a make up column that has no database reference.
                            {
                                sb.Append("			drType[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = string.Empty;");
                            }
                            else
                            {
                                sb.Append("			drType[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = \"" + drv["DataTypeDByteOle"].ToString() + "\";");
                            }
                            sb.Append(" drDisp[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = \"");
                            if (drv["DisplayName"].ToString() == "ImageButton" && drv["DataTypeSysName"].ToString() == "String") { sb.Append("TextBox"); } else { sb.Append(drv["DisplayMode"].ToString()); }
                            sb.Append("\";" + Environment.NewLine);
                        }
                    }
				}
			}
			string sIndent = string.Empty;
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("			if (dv != null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
                sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + "Def\"].Rows.Add(MakeTypRow(ds.Tables[\"" + dw["ProgramName"].ToString() + "Def\"].NewRow()));" + Environment.NewLine);
                sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + "Def\"].Rows.Add(MakeDisRow(ds.Tables[\"" + dw["ProgramName"].ToString() + "Def\"].NewRow()));" + Environment.NewLine);
                if (dw["ScreenTypeName"].ToString() == "I2") { sIndent = "	"; }
			}
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append(sIndent + "			if (bAdd)" + Environment.NewLine);
                sb.Append(sIndent + "			{" + Environment.NewLine);
			}
			if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("					foreach (DataRowView drv in dv)" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				sb.Append("						ds.Tables[\"" + dw["ProgramName"].ToString() + "Add\"].Rows.Add(MakeColRow(ds.Tables[\"" + dw["ProgramName"].ToString() + "Add\"].NewRow(), drv, true));" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
				sb.Append("				else" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
			}
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				// Cannot pass datarow to MakeColRow in case of deleted row:
                sb.Append("					dv.RowStateFilter = DataViewRowState.ModifiedCurrent;" + Environment.NewLine);
				sb.Append("					foreach (DataRowView drv in dv)" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				sb.Append("						ds.Tables[\"" + dw["ProgramName"].ToString() + "Upd\"].Rows.Add(MakeColRow(ds.Tables[\"" + dw["ProgramName"].ToString() + "Upd\"].NewRow(), drv, false));" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("					dv.RowStateFilter = DataViewRowState.Added;" + Environment.NewLine);
				sb.Append("					foreach (DataRowView drv in dv)" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				sb.Append("						ds.Tables[\"" + dw["ProgramName"].ToString() + "Add\"].Rows.Add(MakeColRow(ds.Tables[\"" + dw["ProgramName"].ToString() + "Add\"].NewRow(), drv, true));" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("					dv.RowStateFilter = DataViewRowState.Deleted;" + Environment.NewLine);
				sb.Append("					foreach (DataRowView drv in dv)" + Environment.NewLine);
				sb.Append("					{" + Environment.NewLine);
				sb.Append("						ds.Tables[\"" + dw["ProgramName"].ToString() + "Del\"].Rows.Add(MakeColRow(ds.Tables[\"" + dw["ProgramName"].ToString() + "Del\"].NewRow(), drv, false));" + Environment.NewLine);
				sb.Append("					}" + Environment.NewLine);
				sb.Append("					dv.RowStateFilter = DataViewRowState.CurrentRows;" + Environment.NewLine);
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append("				}" + Environment.NewLine); }
			}
			sb.Append("			}" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("			ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].Rows.Add(dr);");
                sb.Append(" ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].Rows.Add(drType);");
                sb.Append(" ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].Rows.Add(drDisp);" + Environment.NewLine);
            }
			sb.Append("			return ds;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append("		public bool CanAct(char typ) { return CanAct(typ, GetAuthRow(), c" + dw["ProgramName"].ToString() + screenId.ToString() + "List.SelectedValue.ToString()); }" + Environment.NewLine);
            }
            else
            {
                sb.Append("		public bool CanAct(char typ) { return CanAct(typ, GetAuthRow(), null); }" + Environment.NewLine);
            }
            sb.Append(Environment.NewLine);
            sb.Append("		private bool ValidPage()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			EnableValidators(true);" + Environment.NewLine);
			sb.Append("			Page.Validate();" + Environment.NewLine);
            sb.Append("			if (!Page.IsValid) { PanelTop.Update(); return false; }" + Environment.NewLine);
			bool firstValid = true;
			dv.RowFilter = string.Empty;
			foreach (DataRowView drv in dv)
			{
				if (drv["RequiredValid"].ToString() == "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0))
				{
					if (firstValid) {sb.Append("			DataTable dt = null;" + Environment.NewLine); firstValid = false;}
					sb.Append("			dt = (DataTable)Session[KEY_dt" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "];" + Environment.NewLine);
					sb.Append("			if (dt != null && dt.Rows.Count <= 0)" + Environment.NewLine);
					sb.Append("			{" + Environment.NewLine);
                    sb.Append("				bErrNow.Value = \"Y\"; PreMsgPopup(\"Value is expected for '" + drv["ColumnName"].ToString() + "', please investigate.\"); return false;" + Environment.NewLine);
					sb.Append("			}" + Environment.NewLine);
				}
			}
			sb.Append("			return true;" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append(Environment.NewLine);
                sb.Append("		private DataRow MakeTypRow(DataRow dr)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                {
                    sb.Append("			dr[\"" + pMKeyColumn + "\"] = System.Data.OleDb.OleDbType." + pMKeyDByteOle + ".ToString();" + Environment.NewLine);
                    dv.RowFilter = "MasterTable <> 'Y'";
                }
                else { dv.RowFilter = "MasterTable = 'Y'"; }
                foreach (DataRowView drv in dv)
                {
                    if ((drv["TableId"].ToString() != string.Empty
                        && ",Button,DataGrid,PlaceHolder,Label,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0
                        && 
                        (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 
                        || drv["DdlRefColumnId"].ToString() == string.Empty 
                        || drv["DisplayMode"].ToString().ToLower() == "currency") 
                        && (drv["SystemValue"].ToString() == string.Empty || drv["DefAlways"].ToString() != "Y")
                        ) 
                        || drv["DisplayMode"].ToString().ToLower() == "document")
                    {
                        sb.Append("			dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = System.Data.OleDb.OleDbType." + drv["DataTypeDByteOle"].ToString() + ".ToString();" + Environment.NewLine);
                    }
                }
                sb.Append("			return dr;" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		private DataRow MakeDisRow(DataRow dr)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                {
                    sb.Append("			dr[\"" + pMKeyColumn + "\"] = \"" + pMKeyDisplay + "\";" + Environment.NewLine);
                    dv.RowFilter = "MasterTable <> 'Y'";
                }
                else { dv.RowFilter = "MasterTable = 'Y'"; }
                foreach (DataRowView drv in dv)
                {
                    if (
                        (
                        // regardless of table backed or not, it is controlled in data type above
                        (drv["TableId"].ToString() != string.Empty || string.IsNullOrEmpty(drv["TableId"].ToString()))
                            // below are not input, skip in passing to db backend
                            && ",Button,DataGrid,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0
                            && (",ComboBox,DropDownList,ListBox,RadioButtonList,HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 
                                || drv["DdlRefColumnId"].ToString() == string.Empty 
                                || drv["DisplayMode"].ToString().ToLower() == "currency") 
                            && (drv["SystemValue"].ToString() == string.Empty || drv["DefAlways"].ToString() != "Y")
                        ) 
                        || 
                        drv["DisplayMode"].ToString().ToLower() == "document")
                    {
                        sb.Append("			dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = \"" + drv["DisplayMode"].ToString() + "\";" + Environment.NewLine);
                    }
                }
                sb.Append("			return dr;" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
				sb.Append("		private DataRow MakeColRow(DataRow dr, DataRowView drv, bool bAdd)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {sb.Append("			dr[\"" + pMKeyColumn + "\"] = c" + pMKeyColumn + ".Text;" + Environment.NewLine);}
				sb.Append("			DataTable dtAuth = GetAuthCol();" + Environment.NewLine);
				sb.Append("			if (dtAuth != null)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				ii = iOffset;
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dv.RowFilter = "MasterTable <> 'Y'";} else  {dv.RowFilter = "MasterTable = 'Y'";}
				foreach (DataRowView drv in dv)
				{
                    if (
                        (
                        // regardless of table backed or not, controlled by type
                        (drv["TableId"].ToString() != string.Empty || string.IsNullOrEmpty(drv["TableId"].ToString()))
                        // below are not input, skip in passing to db backend
                        && ",Button,DataGrid,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0
                        && 
                        (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 
                            || drv["DdlRefColumnId"].ToString() == string.Empty 
                            || drv["DisplayMode"].ToString().ToLower() == "currency") 
                        && (drv["SystemValue"].ToString() == string.Empty || drv["DefAlways"].ToString() != "Y")
                        ) 
                        || drv["DisplayMode"].ToString().ToLower() == "document")
                    {
                        sb.Append("				dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"]");
                        if (drv["TrimOnEntry"].ToString() == "Y" && drv["DisplayMode"].ToString() == "TextBox") { sb.Append(".ToString().Trim()"); }
                        sb.Append(";" + Environment.NewLine);
                        if (drv["DefaultValue"].ToString() != string.Empty && (drv["DefAfter"].ToString() == "Y" || drv["DefAlways"].ToString() == "Y"))
                        {
                            sb.Append("				dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = ");
                            sb.Append("(drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() == string.Empty && bAdd) " + (drv["DefAlways"].ToString() == "Y" ? " || dtAuth != null " : ""));
                            sb.Append(" ? (object) " + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()) + drv["DefaultValue"].ToString() + Robot.QuoteRequired(false, drv["DataTypeSysName"].ToString(), drv["DefaultValue"].ToString()));
                            sb.Append("	: (object) " + "drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"]");
                            sb.Append(";" + Environment.NewLine);
                        }
						else if (drv["AllowNulls"].ToString() == "Y")
						{
							sb.Append("				if (bAdd && dtAuth.Rows[" + ii.ToString() + "][\"ColReadOnly\"].ToString() == \"Y\" && dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() == string.Empty) {dr[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"] = ");
							sb.Append("System.DBNull.Value;}" + Environment.NewLine);
						}
					}
					ii = ii + 1;
				}
				sb.Append("			}" + Environment.NewLine);
				sb.Append("			return dr;" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
				sb.Append("		private bool UpdateGridRow(object sender, CommandEventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
                sb.Append("			if (c" + dw["ProgramName"].ToString() + "Grid.EditIndex > -1)" + Environment.NewLine);
				sb.Append("			{" + Environment.NewLine);
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dv.RowFilter = "MasterTable <> 'Y'";} else  {dv.RowFilter = "MasterTable = 'Y'";}
                bool bFirstPwd = true;
                bool hasPwdOvride = dv.Cast<DataRowView>().Where(drv => drv["PwdOvride"].ToString() == "Y").Count() > 0;
				foreach (DataRowView drv in dv)
				{
                    if (bFirstPwd && hasPwdOvride) {
                        sb.Append("				TextBox pwd = null;" + Environment.NewLine);
                        bFirstPwd = false;
                    }
					if (drv["PwdOvride"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0)
					{
						sb.Append("				pwd = (TextBox)c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd\");" + Environment.NewLine);
						sb.Append("				if (pwd.Visible) {c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd_TextChanged(c" + dw["ProgramName"].ToString() + "Grid.EditItem.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd\"),new EventArgs());}" + Environment.NewLine);
						sb.Append("				if (pwd.Visible) {return false;}" + Environment.NewLine);
					}
				}
                sb.Append("				c" + dw["ProgramName"].ToString() + "Grid_OnItemUpdating(sender, new ListViewUpdateEventArgs(c" + dw["ProgramName"].ToString() + "Grid.EditIndex));" + Environment.NewLine);
				sb.Append("			}" + Environment.NewLine);
                sb.Append("			return true;" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
				sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnPreRender(object sender, System.EventArgs e)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
                sb.Append("			System.Web.UI.WebControls.Image hi = null;" + Environment.NewLine);
                foreach (DataRowView drv in dv)
                {
                    if (",Button,ImageButton,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString()))
                    {
                        sb.Append("			hi = (System.Web.UI.WebControls.Image)c" + dw["ProgramName"].ToString() + "Grid.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hi\"); if (hi != null) { hi.Visible = false; }" + Environment.NewLine);
                    }
                }
                sb.Append("			if (Session[KEY_lastSortImg] != null)" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
                sb.Append("				hi = (System.Web.UI.WebControls.Image)c" + dw["ProgramName"].ToString() + "Grid.FindControl((string)Session[KEY_lastSortImg]);" + Environment.NewLine);
                sb.Append("				if (hi != null) { hi.ImageUrl = Utils.AddTilde((string)Session[KEY_lastSortUrl]); hi.Visible = true; }" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
                foreach (DataRowView drv in dv)
                {
                    if (",Button,ImageButton,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString()))
                    {
                        sb.Append("			IgnoreHeaderConfirm((LinkButton)c" + dw["ProgramName"].ToString() + "Grid.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hl\"));" + Environment.NewLine);
                    }
                }
                // Take care of CheckBoxAll:
                bool firstCba = true;
                ii = 0;
                dv.RowFilter = string.Empty;	// for dtAuth row #
                foreach (DataRowView drv in dv)
                {
                    if (drv["DisplayMode"].ToString() == "CheckBoxAll")
                    {
                        if (firstCba)
                        {
                            sb.Append(Environment.NewLine + "			// Take care of CheckBoxAll:" + Environment.NewLine);
                            sb.Append("			DataTable dtAuth = GetAuthCol();" + Environment.NewLine);
                            sb.Append("			DataView dv" + dw["ProgramName"].ToString() + "Grid = ((DataTable)Session[KEY_dt" + dw["ProgramName"].ToString() + "Grid]).DefaultView;" + Environment.NewLine);
                            sb.Append("			CheckBox cba = null;" + Environment.NewLine);
                            firstCba = false;
                        }
                        sb.Append("			cba = (CheckBox)c" + dw["ProgramName"].ToString() + "Grid.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hc\");" + Environment.NewLine);
                        sb.Append("			if (cba != null)" + Environment.NewLine);
                        sb.Append("			{" + Environment.NewLine);
                        sb.Append("				if (dtAuth != null && dtAuth.Rows[" + ii.ToString() + "][\"ColReadOnly\"].ToString() == \"Y\") {cba.Enabled = false;}" + Environment.NewLine);
                        sb.Append("				else" + Environment.NewLine);
                        sb.Append("				{" + Environment.NewLine);
                        sb.Append("					int yy = 0;" + Environment.NewLine);
                        sb.Append("					int nn = 0;" + Environment.NewLine);
                        sb.Append("					int zz = 0;" + Environment.NewLine);
                        sb.Append("					foreach (DataRowView drv in dv" + dw["ProgramName"].ToString() + "Grid)" + Environment.NewLine);
                        sb.Append("					{" + Environment.NewLine);
                        sb.Append("						if (drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() == \"Y\") { yy = yy + 1; }" + Environment.NewLine);
                        sb.Append("						else if (drv[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString() == \"N\") { nn = nn + 1; } else { zz = zz + 1; }" + Environment.NewLine);
                        sb.Append("					}" + Environment.NewLine);
                        sb.Append("					int iCnt = dv" + dw["ProgramName"].ToString() + "Grid.Count - zz;" + Environment.NewLine);
                        sb.Append("					if (yy != 0 && yy == iCnt) { b" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + " = true; } else if (nn == iCnt) { b" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + " = false; }" + Environment.NewLine);
                        sb.Append("					cba.Checked = b" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ";" + Environment.NewLine);
                        sb.Append("				}" + Environment.NewLine);
                        sb.Append("				if (cba.Attributes[\"OnClick\"] == null || cba.Attributes[\"OnClick\"].IndexOf(\"ChkPgDirty\") < 0) {cba.Attributes[\"OnClick\"] += \"document.getElementById('\" + bPgDirty.ClientID + \"').value='Y'; ChkPgDirty(); document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
                        sb.Append("			}" + Environment.NewLine);
                    }
                    ii = ii + 1;
                }
                // Take care of aggregates:
                bool firstAggr = true;
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = "MasterTable = 'Y'"; }
                foreach (DataRowView drv in dv)
                {
                    if (drv["AggregateCd"].ToString() != string.Empty)
                    {
                        if (firstAggr)
                        {
                            sb.Append(Environment.NewLine + "			// Take care of aggregates:" + Environment.NewLine);
                            sb.Append("			Label aggr = null;" + Environment.NewLine);
                            firstAggr = false;
                        }
                        sb.Append("			aggr = c" + dw["ProgramName"].ToString() + "Grid.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "fl\") as Label;" + Environment.NewLine);
                        sb.Append("			if (aggr != null) { aggr.Text = ");
                        if (drv["AggregateCd"].ToString() == "C")
                        {
                            sb.Append("RO.Common3.Utils.fmNumeric(\"0\",GetAggr(\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\",\"" + drv["AggregateCd"].ToString() + "\"),base.LUser.Culture)");
                        }
                        else if (drv["DisplayMode"].ToString().ToLower() == "currency")
                        {
                            sb.Append("base.fxCurrency(GetAggr(\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\",\"" + drv["AggregateCd"].ToString() + "\")");
                            sb.Append(string.IsNullOrEmpty(drv["DdlKeyColumnName"].ToString()) ? ",base.LUser.Culture" : ",DataBinder.Eval(Container.DataItem,\"" + drv["DdlKeyColumnName"].ToString() + drv["DdlKeyTableId"].ToString() + "\").ToString()");
                            sb.Append(string.IsNullOrEmpty(drv["DdlRefColumnName"].ToString()) ? ",base.LUser.Culture)" : ",DataBinder.Eval(Container.DataItem,\"" + drv["DdlRefColumnName"].ToString() + drv["DdlRefTableId"].ToString() + "\").ToString())");
                        }
                        else
                        {
                            sb.Append(Robot.DataTypeConvert("Zf", drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), true) + "GetAggr(\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\",\"" + drv["AggregateCd"].ToString() + "\")" + Robot.DataTypeConvert("Zf", drv["DisplayName"].ToString(), drv["DisplayMode"].ToString(), drv["NumericData"].ToString(), drv["ColumnScale"].ToString(), false));
                        }
                        sb.Append("; }" + Environment.NewLine);
                    }
                }
                sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
                sb.Append("		private string GetButtonId(ListViewItem lvi)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			string ButtonID = String.Empty;" + Environment.NewLine);
                //sb.Append("			foreach (TableCell td in tr.Cells)" + Environment.NewLine);
                //sb.Append("			{" + Environment.NewLine);
                //sb.Append("				if (c" + dw["ProgramName"].ToString() + "Grid.Columns[c" + dw["ProgramName"].ToString() + "Grid.Columns.Count-2].Visible)" + Environment.NewLine);
                //sb.Append("				{" + Environment.NewLine);
                //sb.Append("					foreach (Control ctrl in td.Controls)" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                //sb.Append("						if (ctrl.GetType().ToString().IndexOf(\"LinkButton\") >= 0)" + Environment.NewLine);
                //sb.Append("						{" + Environment.NewLine);
                //sb.Append("							if (((LinkButton)ctrl).CommandName.Equals(\"Edit\")) {ButtonID = ((LinkButton)ctrl).UniqueID; break;}" + Environment.NewLine);
                //sb.Append("							else if (((LinkButton)ctrl).CommandName.Equals(\"Cancel\")) {((WebControl) ctrl).Attributes[\"onclick\"] = \"GridCancel();\";}" + Environment.NewLine);
                //sb.Append("						}" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
                //sb.Append("				}" + Environment.NewLine);
                //sb.Append("				else" + Environment.NewLine);
                //sb.Append("				{" + Environment.NewLine);
                //sb.Append("					foreach (Control ctrl in td.Controls)" + Environment.NewLine);
                //sb.Append("					{" + Environment.NewLine);
                //sb.Append("						if (ctrl.GetType().ToString().IndexOf(\"LinkButton\") >= 0)" + Environment.NewLine);
                //sb.Append("						{" + Environment.NewLine);
                //sb.Append("							if (((LinkButton)ctrl).CommandName.Equals(\"Select\")) {ButtonID = ((LinkButton)ctrl).UniqueID; break;}" + Environment.NewLine);
                //sb.Append("						}" + Environment.NewLine);
                //sb.Append("					}" + Environment.NewLine);
                //sb.Append("				}" + Environment.NewLine);
                //sb.Append("				if (ButtonID != String.Empty) {break;}" + Environment.NewLine);
                //sb.Append("			}" + Environment.NewLine);
                sb.Append("			Control c = lvi.FindControl(\"c" + dw["ProgramName"].ToString() + "GridEdit\");" + Environment.NewLine);
                sb.Append("			if (c != null) { ButtonID = c.UniqueID; }" + Environment.NewLine);
                sb.Append("			return ButtonID;" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
				sb.Append(Environment.NewLine);
                sb.Append("		private void SetDefaultCtrl(HtmlTableRow tr, LinkButton lb, string ctrlId)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                sb.Append("			tr.Attributes.Add(\"onclick\", \"document.getElementById('\" + bConfirm.ClientID + \"').value='N'; fFocusedEdit('\" + lb.UniqueID + \"','\" + ctrlId + \"',event);\");" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		private int GetCurrPageIndex()" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                sb.Append("		    return c" + dw["ProgramName"].ToString() + "GridDataPager.StartRowIndex / c" + dw["ProgramName"].ToString() + "GridDataPager.PageSize;" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		private int GetTotalPages()" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                sb.Append("		    return (int)Math.Ceiling((double)c" + dw["ProgramName"].ToString() + "GridDataPager.TotalRowCount / c" + dw["ProgramName"].ToString() + "GridDataPager.PageSize);" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		private int GetDataItemIndex(int editIndex)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                sb.Append("		    return c" + dw["ProgramName"].ToString() + "GridDataPager.StartRowIndex + editIndex;" + Environment.NewLine);
                sb.Append("		}" + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("		protected void c" + dw["ProgramName"].ToString() + "Grid_OnLayoutCreated(object sender, EventArgs e)" + Environment.NewLine);
                sb.Append("		{" + Environment.NewLine);
                sb.Append("		    // Header:" + Environment.NewLine);
                sb.Append("		    LinkButton lb = null;" + Environment.NewLine);
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { dv.RowFilter = "MasterTable <> 'Y'"; } else { dv.RowFilter = "MasterTable = 'Y'"; }
                ii = iOffset;
                foreach (DataRowView drv in dv)
                {
                    sb.Append("		    lb = c" + dw["ProgramName"].ToString() + "Grid.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "hl\") as LinkButton;" + Environment.NewLine);
                    sb.Append("		    if (lb != null) { lb.Text = ColumnHeaderText(" + ii.ToString() + "); lb.ToolTip = ColumnToolTip(" + ii.ToString() + "); lb.Parent.Visible = GridColumnVisible(" + ii.ToString() + "); }" + Environment.NewLine);
                    ii = ii + 1;
                }
                sb.Append("		    // Hide DeleteAll:" + Environment.NewLine);
                sb.Append("			DataTable dtAuthRow = GetAuthRow();" + Environment.NewLine);
                sb.Append("			if (dtAuthRow != null)" + Environment.NewLine);
                sb.Append("			{" + Environment.NewLine);
                sb.Append("				DataRow dr = dtAuthRow.Rows[0];" + Environment.NewLine);
                if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
                {
                    sb.Append("				if ((dr[\"AllowUpd\"].ToString() == \"N\" && dr[\"AllowAdd\"].ToString() == \"N\") || dr[\"ViewOnly\"].ToString() == \"G\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
                }
                else
                {
                    sb.Append("				if (dr[\"AllowDel\"].ToString() == \"N\" || (Request.QueryString[\"enb\"] != null && Request.QueryString[\"enb\"] == \"N\"))" + Environment.NewLine);
                }
                sb.Append("				{" + Environment.NewLine);
                sb.Append("		            lb = c" + dw["ProgramName"].ToString() + "Grid.FindControl(\"cDeleteAllButton\") as LinkButton; if (lb != null) { lb.Visible = false; }" + Environment.NewLine);
                sb.Append("				}" + Environment.NewLine);
                sb.Append("			}" + Environment.NewLine);
                sb.Append("		    // footer:" + Environment.NewLine);
                sb.Append("		    Label gc = null;" + Environment.NewLine);
                ii = iOffset;
                foreach (DataRowView drv in dv)
                {
                    sb.Append("		    gc = c" + dw["ProgramName"].ToString() + "Grid.FindControl(\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "fl\") as Label;" + Environment.NewLine);
                    sb.Append("		    if (gc != null) { gc.Parent.Visible = GridColumnVisible(" + ii.ToString() + "); }" + Environment.NewLine);
                    ii = ii + 1;
                }
                sb.Append("		}" + Environment.NewLine);
			}
			sb.Append(Environment.NewLine);
			sb.Append("		protected void cbPostBack(object sender, System.EventArgs e)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);

            sb.Append(Environment.NewLine);
			sb.Append("		protected void IgnoreHeaderConfirm(LinkButton lb)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("		    if (lb != null && (lb.Attributes[\"OnClick\"] == null || lb.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) && lb.Visible) { lb.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\"; }" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
            
            sb.Append(Environment.NewLine);
			sb.Append("		protected void IgnoreConfirm()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			if (cExpTxtButton.Attributes[\"OnClick\"] == null || cExpTxtButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cExpTxtButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
			sb.Append("			if (cExpRtfButton.Attributes[\"OnClick\"] == null || cExpRtfButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cExpRtfButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
			sb.Append("			if (cUndoAllButton.Attributes[\"OnClick\"] == null || cUndoAllButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cUndoAllButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
            // Do not test visibility of SaveClose button cause it only becomes visible at a much later stage and occasionally:
            sb.Append("			if (cSaveCloseButton.Attributes[\"OnClick\"] == null || cSaveCloseButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cSaveCloseButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
            sb.Append("			if (cSaveButton.Attributes[\"OnClick\"] == null || cSaveButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cSaveButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
            dv.RowFilter = string.Empty;
            foreach (DataRowView drv in dv)
            {
                if (!("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0 && drv["MasterTable"].ToString() == "Y") && ",document,upload,imagebutton,".IndexOf("," + drv["DisplayMode"].ToString().ToLower() + ",") >= 0)
                {
                    sb.Append("			if (cGridUploadBtn.Attributes[\"OnClick\"] == null || cGridUploadBtn.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cGridUploadBtn.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
                    break;
                }
            }
            if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("			if (cInsRowButton.Attributes[\"OnClick\"] == null || cInsRowButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cInsRowButton.Attributes[\"onclick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
                sb.Append("			if (cBrowse.Attributes[\"OnClick\"] == null || cBrowse.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cBrowse.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
				sb.Append("			if (cPgSizeButton.Attributes[\"OnClick\"] == null || cPgSizeButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cPgSizeButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
				sb.Append("			if (cFirstButton.Attributes[\"OnClick\"] == null || cFirstButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cFirstButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
				sb.Append("			if (cPrevButton.Attributes[\"OnClick\"] == null || cPrevButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cPrevButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
				sb.Append("			if (cNextButton.Attributes[\"OnClick\"] == null || cNextButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cNextButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
				sb.Append("			if (cLastButton.Attributes[\"OnClick\"] == null || cLastButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cLastButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
				sb.Append("			if (cFindButton.Attributes[\"OnClick\"] == null || cFindButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cFindButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
				sb.Append("			if (cHideImpButton.Attributes[\"OnClick\"] == null || cHideImpButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cHideImpButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
				sb.Append("			if (cShowImpButton.Attributes[\"OnClick\"] == null || cShowImpButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cShowImpButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
			}
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("			if (cNewSaveButton.Attributes[\"OnClick\"] == null || cNewSaveButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cNewSaveButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
                sb.Append("			if (cCopySaveButton.Attributes[\"OnClick\"] == null || cCopySaveButton.Attributes[\"OnClick\"].IndexOf(\"_bConfirm\") < 0) {cCopySaveButton.Attributes[\"OnClick\"] += \"document.getElementById('\" + bConfirm.ClientID + \"').value='N';\";}" + Environment.NewLine);
                //To reconfirm delete and clear.
				sb.Append("			if (cDeleteButton.Attributes[\"OnClick\"] == null || cDeleteButton.Attributes[\"OnClick\"].IndexOf(\"return confirm\") < 0) {cDeleteButton.Attributes[\"OnClick\"] += \"return confirm('Delete this record for sure?');\";}" + Environment.NewLine);
				sb.Append("			if (cClearButton.Attributes[\"OnClick\"] == null || cClearButton.Attributes[\"OnClick\"].IndexOf(\"return confirm\") < 0) {cClearButton.Attributes[\"OnClick\"] += \"return confirm('Clear this record for sure and assume initial defaulted values except non-editable fields? You may click the New button if you wish to create a new record instead.');\";}" + Environment.NewLine);
			}
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		protected void InitPreserve()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
            sb.Append("			cSystemId.Attributes[\"onchange\"] = \"javascript:return CanPostBack(true,this);\";cSystemId.Attributes[\"NeedConfirm\"] = \"Y\";" + Environment.NewLine);
            sb.Append("			cFilterId.Attributes[\"onchange\"] = \"javascript:return CanPostBack(true,this);\";cFilterId.Attributes[\"NeedConfirm\"] = \"Y\";" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			sb.Append("		protected void ShowDirty(bool bShow)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			sb.Append("			if (bShow) {bPgDirty.Value = \"Y\";} else {bPgDirty.Value = \"N\";}" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append("		private void PreMsgPopup(string msg) { PreMsgPopup(msg");
            if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
            {
                sb.Append(",c" + dw["ProgramName"].ToString() + screenId.ToString() + "List");
            }
            else
            {
                sb.Append(",null");
            }
            sb.Append(",null); }" + Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append("		private void PreMsgPopup(string msg, RoboCoder.WebControls.ComboBox cb, WebControl wc)" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
            sb.Append("		    if (string.IsNullOrEmpty(msg)) return;" + Environment.NewLine);
            sb.Append("		    if (IsCronInvoked()) { ErrorTrace(new Exception(msg), bErrNow.Value == \"N\" ? \"warning\" : \"error\"); return; }" + Environment.NewLine);
            sb.Append("		    int MsgPos = msg.IndexOf(\"RO.SystemFramewk.ApplicationAssert\");" + Environment.NewLine);
            sb.Append("		    string iconUrl = \"images/warning.gif\";" + Environment.NewLine);    // Client-side no '~/'.
            sb.Append("		    string focusOnCloseId = cb != null ? cb.FocusID : (wc != null ? wc.ClientID : string.Empty);" + Environment.NewLine);
            sb.Append("		    string msgContent = ReformatErrMsg(msg);" + Environment.NewLine);
            sb.Append("		    if (MsgPos >= 0 && LUser.TechnicalUsr != \"Y\") { msgContent = ReformatErrMsg(msg.Substring(0, MsgPos - 3)); }" + Environment.NewLine);
            sb.Append("		    if (bErrNow.Value == \"Y\") { iconUrl = \"images/error.gif\"; bErrNow.Value = \"N\"; }" + Environment.NewLine);  // Client-side no '~/'.
            sb.Append("		    else if (bInfoNow.Value == \"Y\") { iconUrl = \"images/info.gif\"; bInfoNow.Value = \"N\"; }" + Environment.NewLine);  // Client-side no '~/'.
            sb.Append("			string script =" + Environment.NewLine);
            sb.Append("			@\"<script type='text/javascript' lang='javascript'>" + Environment.NewLine);
            sb.Append("			PopDialog('\" + iconUrl + \"','\" + msgContent.Replace(@\"\\\", @\"\\\\\").Replace(\"'\", @\"\\'\") + \"','\" + focusOnCloseId + @\"');" + Environment.NewLine);
            sb.Append("			</script>\";" + Environment.NewLine);
            sb.Append("			ScriptManager.RegisterStartupScript(cMsgContent, typeof(Label), \"Popup\", script, false);" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append("		private Control FindEditableControl(Control root)" + Environment.NewLine);
            sb.Append("		{" + Environment.NewLine);
            sb.Append("		    Control found = null;" + Environment.NewLine);
            sb.Append("		    if (IsEditableControl(root)) { found = root; return found; }" + Environment.NewLine);
            sb.Append("		    foreach (Control c in root.Controls)" + Environment.NewLine);
            sb.Append("		    {" + Environment.NewLine);
            sb.Append("		        found = FindEditableControl(c); if (found != null) return found;" + Environment.NewLine);
            sb.Append("		    }" + Environment.NewLine);
            sb.Append("		    return null;" + Environment.NewLine);
            sb.Append("		}" + Environment.NewLine);
            sb.Append("	}" + Environment.NewLine);
			sb.Append("}" + Environment.NewLine);
			sb.Append(Environment.NewLine);
			return sb;
		}

        //private StringBuilder MakeSystemCs(DataRow dw, Int32 screenId, DataView dv, DataTable dtLis, DataTable dtDtl, DataView dvARule, string appDatabase, string sysDatabase, CurrPrj CPrj, CurrSrc CSrc)
        //{
        //    string pMKey = string.Empty;
        //    //bool firstWord = true;
        //    bool bRemove = false;
        //    //DataTable dt = null;
        //    StringBuilder parameterNames = new StringBuilder();
        //    StringBuilder parameterTypes = new StringBuilder();
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("using System;" + Environment.NewLine);
        //    sb.Append("using System.Data;" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ";" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ".Data;" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Rule" + CSrc.SrcSystemId.ToString() + ";" + Environment.NewLine);
        //    if (CSrc.SrcSystemId != 3)	// Admin.
        //    {
        //        sb.Append("using RO.Common3;" + Environment.NewLine);
        //        sb.Append("using RO.Common3.Data;" + Environment.NewLine);
        //        sb.Append("using RO.Rule3;" + Environment.NewLine);
        //    }
        //    sb.Append(Environment.NewLine);
        //    sb.Append("namespace " + CPrj.EntityCode + ".Facade" + CSrc.SrcSystemId.ToString() + Environment.NewLine);
        //    sb.Append("{" + Environment.NewLine);
        //    sb.Append("	public class " + dw["ProgramName"].ToString() + "System : MarshalByRefObject" + Environment.NewLine);
        //    sb.Append("	{" + Environment.NewLine);
        //    dv.RowFilter = string.Empty;
        //    foreach (DataRowView drv in dv)
        //    {
        //        if (drv["MasterTable"].ToString() == "Y" && drv["PrimaryKey"].ToString() == "Y")
        //        {
        //            pMKey = drv["ColumnName"].ToString(); break;
        //        }
        //    }
        //    foreach (DataRowView drv in dv)
        //    {
        //        if (drv["DisplayMode"].ToString().ToLower() == "document")
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("		public string Del" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(string MasterId, string DocId, string UsrId, string dbConnectionString, string dbPassword)" + Environment.NewLine);
        //            sb.Append("		{" + Environment.NewLine);
        //            sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				return dac.Del" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(MasterId, DocId, UsrId, dbConnectionString, dbPassword);" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("		}" + Environment.NewLine);
        //        }
        //        //if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
        //        //{
        //        //    using (GenScreensAccessBase dac = GetGenScreensAccess())
        //        //    {
        //        //        dt = dac.GetScreenObjDdlById(screenId, Int32.Parse(drv["ScreenObjId"].ToString()), "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString(), "N", appDatabase, sysDatabase, CPrj.SrcDesDatabase, pMKey, drv["MultiDesignDb"].ToString(), CSrc);
        //        //    }
        //        //    bRemove = false;
        //        //    dvARule.RowFilter = "RuleLayerCd = 'S' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        //    foreach (DataRowView dra in dvARule)
        //        //    {
        //        //        if (dra["RmFuncProc"].ToString() == "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString()) { bRemove = true; break; }
        //        //    }
        //        //    if (!bRemove)
        //        //    {
        //        //        sb.Append(Environment.NewLine);
        //        //        sb.Append("		public DataTable GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "(Int32 screenId, bool bAll, int topN, ");
        //        //        parameterNames.Remove(0, parameterNames.Length);
        //        //        parameterTypes.Remove(0, parameterTypes.Length);
        //        //        parameterNames.Append(dt.Rows[0]["parameter2Names"].ToString());
        //        //        parameterTypes.Append(dt.Rows[0]["parameter2Types"].ToString());
        //        //        firstWord = true;
        //        //        while (parameterNames.Length > 0 && parameterTypes.Length > 0)
        //        //        {
        //        //            if (firstWord) { firstWord = false; } else { sb.Append(", "); }
        //        //            sb.Append(Utils.PopFirstWord(parameterTypes, (char)44) + " " + Utils.PopFirstWord(parameterNames, (char)44));
        //        //        }
        //        //        sb.Append(Robot.GetCnDclr(drv["MultiDesignDb"].ToString(), "N") + ",string filterTxt, UsrImpr ui, UsrCurr uc)" + Environment.NewLine);
        //        //        sb.Append("		{" + Environment.NewLine);
        //        //        sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //        //        sb.Append("			{" + Environment.NewLine);
        //        //        sb.Append("				return dac.GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "(screenId,bAll,topN," + dt.Rows[0]["parameter2Names"].ToString() + Robot.GetCnParm(drv["MultiDesignDb"].ToString(), "N") + ",filterTxt,ui,uc);" + Environment.NewLine);
        //        //        sb.Append("			}" + Environment.NewLine);
        //        //        sb.Append("		}" + Environment.NewLine);
        //        //    }
        //        //}
        //    }
        //    //if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'S' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "GetExp" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("		public DataTable GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "(string useGlobalFilter, Int32 screenId");
        //    //        sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ", Int32 screenFilterId, DataView dvCri, UsrImpr ui, UsrCurr uc, DataSet ds)" + Environment.NewLine);
        //    //        sb.Append("		{" + Environment.NewLine);
        //    //        sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("				return dac.GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "(useGlobalFilter,screenId" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",screenFilterId,dvCri,ui,uc,ds);" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("		}" + Environment.NewLine);
        //    //    }
        //    //}
        //    //bRemove = false;
        //    //dvARule.RowFilter = "RuleLayerCd = 'S' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //foreach (DataRowView dra in dvARule)
        //    //{
        //    //    if (dra["RmFuncProc"].ToString() == "GetLis" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    //}
        //    //if (!bRemove)
        //    //{
        //    //    sb.Append(Environment.NewLine);
        //    //    sb.Append("		public DataTable GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "(string useGlobalFilter, Int32 screenId,int topN");
        //    //    sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ", Int32 screenFilterId, string key, string filterTxt, DataView dvCri, UsrImpr ui, UsrCurr uc, DataSet ds)" + Environment.NewLine);
        //    //    sb.Append("		{" + Environment.NewLine);
        //    //    sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //    //    sb.Append("			{" + Environment.NewLine);
        //    //    sb.Append("				return dac.GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "(useGlobalFilter,screenId,topN" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",screenFilterId,key,filterTxt,dvCri,ui,uc,ds);" + Environment.NewLine);
        //    //    sb.Append("			}" + Environment.NewLine);
        //    //    sb.Append("		}" + Environment.NewLine);
        //    //}
        //    //if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'S' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById") { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("		public DataTable Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById(");
        //    //        parameterNames.Remove(0, parameterNames.Length);
        //    //        parameterNames.Append(dtLis.Rows[0]["parameter2Names"].ToString());
        //    //        firstWord = true;
        //    //        while (parameterNames.Length > 0)
        //    //        {
        //    //            if (firstWord) { firstWord = false; } else { sb.Append(", "); }
        //    //            sb.Append("string " + Utils.PopFirstWord(parameterNames, (char)44));
        //    //        }
        //    //        sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //    //        sb.Append("		{" + Environment.NewLine);
        //    //        sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("				return dac.Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById(" + dtLis.Rows[0]["parameter2Names"].ToString() + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("		}" + Environment.NewLine);
        //    //    }
        //    //}
        //    //if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'S' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById") { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("		public DataTable Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById(Int32 screenId, ");
        //    //        parameterNames.Remove(0, parameterNames.Length);
        //    //        parameterNames.Append(dtDtl.Rows[0]["parameter2Names"].ToString());
        //    //        firstWord = true;
        //    //        while (parameterNames.Length > 0)
        //    //        {
        //    //            if (firstWord) { firstWord = false; } else { sb.Append(", "); }
        //    //            sb.Append("string " + Utils.PopFirstWord(parameterNames, (char)44));
        //    //        }
        //    //        sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ", Int32 screenFilterId, UsrImpr ui, UsrCurr uc)" + Environment.NewLine);
        //    //        sb.Append("		{" + Environment.NewLine);
        //    //        sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("				return dac.Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById(screenId," + dtDtl.Rows[0]["parameter2Names"].ToString() + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ",screenFilterId,ui,uc);" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("		}" + Environment.NewLine);
        //    //    }
        //    //}
        //    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    {
        //        bRemove = false;
        //        dvARule.RowFilter = "RuleLayerCd = 'S' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Add" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //        }
        //        if (!bRemove)
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("		public string Add" + dw["ProgramName"].ToString() + screenId.ToString() + "(LoginUsr lu, UsrImpr ui, UsrCurr uc, " + dw["ProgramName"].ToString() + screenId.ToString() + " ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //            sb.Append("		{" + Environment.NewLine);
        //            sb.Append("			return (new " + dw["ProgramName"].ToString() + "Rules()).Add" + dw["ProgramName"].ToString() + screenId.ToString() + "(lu,ui,uc,ds" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //            sb.Append("		}" + Environment.NewLine);
        //        }
        //        bRemove = false;
        //        dvARule.RowFilter = "RuleLayerCd = 'S' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Del" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //        }
        //        if (!bRemove)
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("		public bool Del" + dw["ProgramName"].ToString() + screenId.ToString() + "(LoginUsr lu, UsrImpr ui, UsrCurr uc, " + dw["ProgramName"].ToString() + screenId.ToString() + " ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //            sb.Append("		{" + Environment.NewLine);
        //            sb.Append("			return (new " + dw["ProgramName"].ToString() + "Rules()).Del" + dw["ProgramName"].ToString() + screenId.ToString() + "(lu,ui,uc,ds" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //            sb.Append("		}" + Environment.NewLine);
        //        }
        //    }
        //    bRemove = false;
        //    dvARule.RowFilter = "RuleLayerCd = 'S' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    foreach (DataRowView dra in dvARule)
        //    {
        //        if (dra["RmFuncProc"].ToString() == "Upd" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    }
        //    if (!bRemove)
        //    {
        //        sb.Append(Environment.NewLine);
        //        sb.Append("		public bool Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "(LoginUsr lu, UsrImpr ui, UsrCurr uc, " + dw["ProgramName"].ToString() + screenId.ToString() + " ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //        sb.Append("		{" + Environment.NewLine);
        //        sb.Append("			return (new " + dw["ProgramName"].ToString() + "Rules()).Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "(lu,ui,uc,ds" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //        sb.Append("		}" + Environment.NewLine);
        //    }
        //    //if (dvCri.Count > 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'S' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "Upd" + dw["ProgramName"].ToString() + "In") { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("		public bool Upd" + dw["ProgramName"].ToString() + "In(Int32 screenId, Int32 usrId, bool isCriVisible, " + dw["ProgramName"].ToString() + screenId.ToString() + "In ds" + Robot.GetCnDclr("N", "N") + ")" + Environment.NewLine);
        //    //        sb.Append("		{" + Environment.NewLine);
        //    //        sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("				return dac.Upd" + dw["ProgramName"].ToString() + "In(screenId, usrId, isCriVisible, ds" + Robot.GetCnParm("N", "N") + ");" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("		}" + Environment.NewLine);
        //    //    }
        //    //}
        //    dvARule.RowFilter = "RuleLayerCd = 'S'";
        //    foreach (DataRowView dra in dvARule)
        //    {
        //        sb.Append(Environment.NewLine);
        //        sb.Append("		//AdvRule: " + dra["RuleName"].ToString() + Environment.NewLine);
        //        sb.Append("		" + dra["AdvRuleProg"].ToString() + Environment.NewLine);
        //        sb.Append("		// *** AdvRule End *** //" + Environment.NewLine);
        //    }
        //    sb.Append("	}" + Environment.NewLine);
        //    sb.Append("}" + Environment.NewLine);
        //    return sb;
        //}

        //private StringBuilder MakeRulesCs(DataRow dw, Int32 screenId, DataView dv, DataTable dtLis, DataTable dtDtl, DataView dvARule, CurrPrj CPrj, CurrSrc CSrc)
        //{
        //    bool bRemove = false;
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("using System;" + Environment.NewLine);
        //    sb.Append("using System.Data;" + Environment.NewLine);
        //    sb.Append("using System.Data.OleDb;" + Environment.NewLine);
        //    sb.Append("using System.Text.RegularExpressions;" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ";" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ".Data;" + Environment.NewLine);
        //    if (CSrc.SrcSystemId != 3)	// Admin.
        //    {
        //        sb.Append("using RO.Common3;" + Environment.NewLine);
        //        sb.Append("using RO.Common3.Data;" + Environment.NewLine);
        //    }
        //    sb.Append("using RO.SystemFramewk;" + Environment.NewLine);
        //    sb.Append(Environment.NewLine);
        //    sb.Append("namespace " + CPrj.EntityCode + ".Rule" + CSrc.SrcSystemId.ToString() + Environment.NewLine);
        //    sb.Append("{" + Environment.NewLine);
        //    sb.Append("	public class " + dw["ProgramName"].ToString() + "Rules" + Environment.NewLine);
        //    sb.Append("	{" + Environment.NewLine);
        //    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    {
        //        bRemove = false;
        //        dvARule.RowFilter = "RuleLayerCd = 'R' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Add" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //        }
        //        if (!bRemove)
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("		public string Add" + dw["ProgramName"].ToString() + screenId.ToString() + "(LoginUsr LUser, UsrImpr LImpr, UsrCurr LCurr, " + dw["ProgramName"].ToString() + screenId.ToString() + " ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //            sb.Append("		{" + Environment.NewLine);
        //            sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				return dac.Add" + dw["ProgramName"].ToString() + screenId.ToString() + "(LUser,LImpr,LCurr,ds" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("		}" + Environment.NewLine);
        //        }
        //        bRemove = false;
        //        dvARule.RowFilter = "RuleLayerCd = 'R' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Del" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //        }
        //        if (!bRemove)
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("		public bool Del" + dw["ProgramName"].ToString() + screenId.ToString() + "(LoginUsr LUser, UsrImpr LImpr, UsrCurr LCurr, " + dw["ProgramName"].ToString() + screenId.ToString() + " ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //            sb.Append("		{" + Environment.NewLine);
        //            sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				return dac.Del" + dw["ProgramName"].ToString() + screenId.ToString() + "(LUser,LImpr,LCurr,ds" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("		}" + Environment.NewLine);
        //        }
        //    }
        //    bRemove = false;
        //    dvARule.RowFilter = "RuleLayerCd = 'R' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    foreach (DataRowView dra in dvARule)
        //    {
        //        if (dra["RmFuncProc"].ToString() == "Upd" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    }
        //    if (!bRemove)
        //    {
        //        sb.Append(Environment.NewLine);
        //        sb.Append("		public bool Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "(LoginUsr LUser, UsrImpr LImpr, UsrCurr LCurr, " + dw["ProgramName"].ToString() + screenId.ToString() + " ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //        sb.Append("		{" + Environment.NewLine);
        //        sb.Append("			using (Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access dac = new Access" + CSrc.SrcSystemId.ToString() + "." + dw["ProgramName"].ToString() + "Access())" + Environment.NewLine);
        //        sb.Append("			{" + Environment.NewLine);
        //        sb.Append("				return dac.Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "(LUser,LImpr,LCurr,ds" + Robot.GetCnParm(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //        sb.Append("			}" + Environment.NewLine);
        //        sb.Append("		}" + Environment.NewLine);
        //    }
        //    dvARule.RowFilter = "RuleLayerCd = 'R'";
        //    foreach (DataRowView dra in dvARule)
        //    {
        //        sb.Append(Environment.NewLine);
        //        sb.Append("		//AdvRule: " + dra["RuleName"].ToString() + Environment.NewLine);
        //        sb.Append("		" + dra["AdvRuleProg"].ToString() + Environment.NewLine);
        //        sb.Append("		// *** AdvRule End *** //" + Environment.NewLine);
        //    }
        //    sb.Append("	}" + Environment.NewLine);
        //    sb.Append("}" + Environment.NewLine);
        //    return sb;
        //}

		private void MakeRulesCsPrepRule(DataRow dw, StringBuilder sb, DataView dvSRule, string firingEvent, string beforeCRUD)
		{
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				string varParam = string.Empty;
				bool firstWord = true;
				StringBuilder callingParams = new StringBuilder();
				dvSRule.RowFilter = "MasterTable = 'Y'";
				foreach (DataRowView drv in dvSRule)
				{
					if (drv["On" + firingEvent].ToString() == "Y" && drv["BeforeCRUD"].ToString() == beforeCRUD)
					{
						sb.Append("				");
						if (dw["DeferError"].ToString() == "Y") {sb.Append("try {");}
						sb.Append(drv["ProcedureName"].ToString() + "(");
						firstWord = true;
						callingParams.Remove(0,callingParams.Length);
						callingParams.Append(drv["CallingParams"].ToString());
						string ErrParam = "\"" + drv["ProcedureName"].ToString() + "\"";
						while (callingParams.Length > 0)
						{
							if (firstWord) {firstWord = false;} else {sb.Append(", ");}
							varParam = Utils.PopFirstWord(callingParams,(char)44);
							if (varParam.ToString().ToLower() == "null") {sb.Append("string.Empty");}
							else if (varParam.IndexOf("LUser.") >= 0 || varParam.IndexOf("LImpr.") >= 0 || varParam.IndexOf("LCurr.") >= 0 || varParam.IndexOf("Config.") >= 0) { sb.Append(varParam + ".ToString()"); }
							else {sb.Append("row[\"" + varParam + "\"].ToString()"); ErrParam = "row[\"" + varParam + "\"].ToString()";}
						}
						if (!firstWord) {sb.Append(",");}
						sb.Append("cn,tr);");
						if (dw["DeferError"].ToString() == "Y") { sb.Append("} catch (Exception e) {bHasErr = true; ErrLst[\"" + drv["ProcedureName"].ToString() + " \" + " + ErrParam + "] = e.Message;}"); }
						sb.Append(Environment.NewLine);
					}
				}
			}
		}

		private void MakeRulesCsPrepDtlRule(DataRow dw, StringBuilder sb, DataView dvSRule, string firingEvent, string beforeCRUD)
		{
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				string varParam = string.Empty;
				bool firstWord = true;
				StringBuilder callingParams = new StringBuilder();
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dvSRule.RowFilter = "MasterTable <> 'Y'";} else  {dvSRule.RowFilter = "MasterTable = 'Y'";}
				foreach (DataRowView drv in dvSRule)
				{
					if (drv["On" + firingEvent].ToString() == "Y" && drv["BeforeCRUD"].ToString() == beforeCRUD)
					{
						sb.Append("				rows = ds.Tables[\"" + dw["ProgramName"].ToString() + "" + firingEvent + "\"].Rows;" + Environment.NewLine);
						sb.Append("				for (int ii = 0; ii < rows.Count; ii++)" + Environment.NewLine);
						sb.Append("				{" + Environment.NewLine);
						sb.Append("					");
						if (dw["DeferError"].ToString() == "Y") { sb.Append("try {"); }
						sb.Append(drv["ProcedureName"].ToString() + "(");
						firstWord = true;
						callingParams.Remove(0,callingParams.Length);
						callingParams.Append(drv["CallingParams"].ToString());
						string ErrParam = "\"" + drv["ProcedureName"].ToString() + "\"";
						while (callingParams.Length > 0)
						{
							if (firstWord) {firstWord = false;} else {sb.Append(", ");}
							varParam = Utils.PopFirstWord(callingParams,(char)44);
							if (varParam.ToString().ToLower() == "null") {sb.Append("string.Empty");}
							else if (varParam.IndexOf("LUser.") >= 0 || varParam.IndexOf("LImpr.") >= 0 || varParam.IndexOf("LCurr.") >= 0 || varParam.IndexOf("Config.") >= 0) { sb.Append(varParam + ".ToString()"); }
							else {sb.Append("rows[ii][\"" + varParam + "\"].ToString()"); ErrParam = "rows[ii][\"" + varParam + "\"].ToString()";}
						}
						if (!firstWord) {sb.Append(",");}
						sb.Append("cn,tr);");
						if (dw["DeferError"].ToString() == "Y") { sb.Append("} catch (Exception e) {bHasErr = true; ErrLst[\"" + drv["ProcedureName"].ToString() + " \" + " + ErrParam + "] = e.Message;}"); }
						sb.Append(Environment.NewLine);
						sb.Append("				}" + Environment.NewLine);
					}
				}
			}
			return;
		}

		private void PrepDtlSp(DataRow dw, Int32 screenId, DataView dv, StringBuilder sb, string evn, string pMKeyColumn, string pMKeyIdentity, string pDKeyColumn, string pDKeyIdentity)
		{
			string pKeyIdentity;
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				if ("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {pKeyIdentity = pMKeyIdentity;} else {pKeyIdentity = pDKeyIdentity;}
				sb.Append("				rows = ds.Tables[\"" + dw["ProgramName"].ToString() + "" + evn + "\"].Rows;" + Environment.NewLine);
				sb.Append("				for ( int ii = 0; ii < rows.Count; ii++ )" + Environment.NewLine);
				sb.Append("				{" + Environment.NewLine);
				sb.Append("					");
				if (evn == "Add" && pKeyIdentity == "Y")
				{
					sb.Append("rows[ii][\"");
					if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {sb.Append(pDKeyColumn + "\"] = ");} else {sb.Append(pMKeyColumn + "\"] = ");}
				}
				sb.Append(evn + dw["ProgramName"].ToString() + screenId.ToString() + "Dt(");
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					if (evn == "Add") {sb.Append("row[\"" + pMKeyColumn + "\"].ToString(),");}
					sb.Append("rows[ii][\"" + pDKeyColumn + "\"].ToString(),");
				}
				else {sb.Append("rows[ii][\"" + pMKeyColumn + "\"].ToString(),");}
				if (evn != "Del")
				{
					if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dv.RowFilter = "MasterTable <> 'Y'";} else  {dv.RowFilter = "MasterTable = 'Y'";}
					foreach (DataRowView drv in dv)
					{
                        if ((drv["PrimaryKey"].ToString() != "Y" && drv["TableId"].ToString() != string.Empty && (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DdlRefColumnId"].ToString() == string.Empty || drv["DisplayMode"].ToString().ToLower() == "currency") && (drv["SystemValue"].ToString() == string.Empty || drv["DefAlways"].ToString() != "Y")) || drv["DisplayMode"].ToString().ToLower() == "document")
                        {
							sb.Append("rows[ii][\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"].ToString(),");
						}
					}
				}
				sb.Append("cn,tr);" + Environment.NewLine);
				sb.Append("				}" + Environment.NewLine);
			}
		}

        //private void MakeDtlSp(DataRow dw, Int32 screenId, DataView dv, StringBuilder sb, string evn, string pMKeyColumn, string pMKeySByteOle, string pMKeySysName, string pMKeyIdentity, string pDKeyColumn, string pDKeySByteOle, string pDKeySysName, string pDKeyIdentity, DataTable dtCud)
        //{
        //    string pKeySysName;
        //    string pKeyIdentity;
        //    if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    {
        //        if ("I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //        {
        //            pKeySysName = pMKeySysName; pKeyIdentity = pMKeyIdentity;
        //        }
        //        else
        //        {
        //            pKeySysName = pDKeySysName; pKeyIdentity = pDKeyIdentity;
        //        }
        //        sb.Append(Environment.NewLine);
        //        sb.Append("		public ");
        //        if (evn == "Add" && pKeyIdentity == "Y") {sb.Append(pKeySysName);} else {sb.Append("void");}
        //        sb.Append(" " + evn + dw["ProgramName"].ToString() + screenId.ToString() + "Dt(");
        //        if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //        {
        //            if (evn == "Add") {sb.Append("string " + pMKeyColumn + ", ");}
        //            sb.Append("string " + pDKeyColumn + ", ");
        //        }
        //        else {sb.Append("string " + pMKeyColumn + ", ");}
        //        if (evn != "Del")
        //        {
        //            if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dv.RowFilter = "MasterTable <> 'Y'";} else  {dv.RowFilter = "MasterTable = 'Y'";}
        //            foreach (DataRowView drv in dv)
        //            {
        //                if ((drv["PrimaryKey"].ToString() != "Y" && drv["TableId"].ToString() != string.Empty && (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DdlRefColumnId"].ToString() == string.Empty) && (drv["SystemValue"].ToString() == string.Empty || drv["DefAlways"].ToString() != "Y")) || drv["DisplayMode"].ToString().ToLower() == "document")
        //                {
        //                    sb.Append("string " + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ", ");
        //                }
        //            }
        //        }
        //        sb.Append("OleDbConnection cn, OleDbTransaction tr)" + Environment.NewLine);
        //        sb.Append("		{" + Environment.NewLine);
        //        sb.Append("			OleDbCommand cmd = new OleDbCommand(\"SET NOCOUNT ON\"");
        //        if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //        {
        //            if (evn == "Del") {sb.Append(dtCud.Rows[3][0].ToString() + ", cn);" + Environment.NewLine);}
        //            else if (evn == "Add") {sb.Append(dtCud.Rows[4][0].ToString() + ", cn);" + Environment.NewLine);}
        //            else {sb.Append(dtCud.Rows[5][0].ToString() + ", cn);" + Environment.NewLine);}
        //        }
        //        else
        //        {
        //            if (evn == "Del") {sb.Append(dtCud.Rows[0][0].ToString() + ", cn);" + Environment.NewLine);}
        //            else if (evn == "Add") {sb.Append(dtCud.Rows[1][0].ToString() + ", cn);" + Environment.NewLine);}
        //            else {sb.Append(dtCud.Rows[2][0].ToString() + ", cn);" + Environment.NewLine);}
        //        }
        //        sb.Append("			cmd.CommandType = CommandType.Text;" + Environment.NewLine);
        //        if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //        {
        //            if (evn == "Add") {sb.Append("			cmd.Parameters.Add(\"@" + pMKeyColumn + "\", OleDbType." + pMKeySByteOle + ").Value = " + pMKeyColumn + ";" + Environment.NewLine);}
        //            sb.Append("			if (" + pDKeyColumn + " == string.Empty)" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				cmd.Parameters.Add(\"@" + pDKeyColumn + "\", OleDbType." + pDKeySByteOle + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			else" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				cmd.Parameters.Add(\"@" + pDKeyColumn + "\", OleDbType." + pDKeySByteOle + ").Value = " + pDKeyColumn + ";" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //        }
        //        else
        //        {
        //            sb.Append("			if (" + pMKeyColumn + " == string.Empty)" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				cmd.Parameters.Add(\"@" + pMKeyColumn + "\", OleDbType." + pMKeySByteOle + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			else" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				cmd.Parameters.Add(\"@" + pMKeyColumn + "\", OleDbType." + pMKeySByteOle + ").Value = " + pMKeyColumn + ";" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //        }
        //        if (evn != "Del")
        //        {
        //            if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {dv.RowFilter = "MasterTable <> 'Y'";} else  {dv.RowFilter = "MasterTable = 'Y'";}
        //            foreach (DataRowView drv in dv)
        //            {
        //                if ((drv["PrimaryKey"].ToString() != "Y" && drv["TableId"].ToString() != string.Empty && (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DdlRefColumnId"].ToString() == string.Empty) && (drv["SystemValue"].ToString() == string.Empty || drv["DefAlways"].ToString() != "Y")) || drv["DisplayMode"].ToString().ToLower() == "document")
        //                {
        //                    sb.Append("			if (" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".Trim() == string.Empty)" + Environment.NewLine);
        //                    sb.Append("			{" + Environment.NewLine);
        //                    if (drv["RequiredValid"].ToString() == "N")
        //                    {
        //                        sb.Append("				cmd.Parameters.Add(\"@" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //                    }
        //                    else
        //                    {
        //                        sb.Append("				ApplicationAssert.CheckCondition(false, string.Empty, string.Empty, \"Value is expected for " + drv["DisplayName"].ToString() + " '" + drv["ColumnName"].ToString() + "', please check data grid and try again!\");" + Environment.NewLine);
        //                    }
        //                    sb.Append("			}" + Environment.NewLine);
        //                    sb.Append("			else" + Environment.NewLine);
        //                    sb.Append("			{" + Environment.NewLine);
        //                    if (drv["DataTypeSByteOle"].ToString() == drv["DataTypeDByteOle"].ToString())
        //                    {
        //                        if (",SmallDateTime,DateTime,".IndexOf("," + drv["DataTypeSqlName"].ToString() + ",") >= 0)
        //                        {
        //                            sb.Append("				if (" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ".ToString() != string.Empty) {try {Convert.ToDateTime(" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + ");} catch {ApplicationAssert.CheckCondition(false,\"Add" + dw["ProgramName"].ToString() + screenId.ToString() + "Dt\", \"DateTime Error\", \"Please enter a valid date and try again.\");}}" + Environment.NewLine);
        //                        }
        //                        sb.Append("				cmd.Parameters.Add(\"@" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = " + Robot.ChkHash(drv["DisplayMode"].ToString(), drv["ColumnName"].ToString() + drv["TableId"].ToString(), drv["TrimOnEntry"].ToString()) + ";" + Environment.NewLine);
        //                    }
        //                    else
        //                    {
        //                        sb.Append("				if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeDByteOle"].ToString() + ").Value = " + Robot.ChkHash(drv["DisplayMode"].ToString(), drv["ColumnName"].ToString() + drv["TableId"].ToString(), drv["TrimOnEntry"].ToString()) + ";} else {cmd.Parameters.Add(\"@" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = " + Robot.ChkHash(drv["DisplayMode"].ToString(), drv["ColumnName"].ToString() + drv["TableId"].ToString(), drv["TrimOnEntry"].ToString()) + ";}" + Environment.NewLine);
        //                    }
        //                    sb.Append("			}" + Environment.NewLine);
        //                }
        //            }
        //        }
        //        sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //        sb.Append("			cmd.Transaction = tr;" + Environment.NewLine);
        //        if (evn == "Add" && pKeyIdentity == "Y")
        //        {
        //            // Do not use ExecuteScalar() as Sybase may deadlock.
        //            sb.Append("			da.SelectCommand = cmd;" + Environment.NewLine);
        //            sb.Append("			DataTable dt = new DataTable();" + Environment.NewLine);
        //            sb.Append("			da.Fill(dt);" + Environment.NewLine);
        //            sb.Append("			" + pKeySysName + " id = " + Robot.ParseRequired(pKeySysName,true) + "dt.Rows[0][0].ToString()" + Robot.ParseRequired(pKeySysName,false) + ";" + Environment.NewLine);
        //        }
        //        else
        //        {
        //            sb.Append("			cmd.ExecuteNonQuery();" + Environment.NewLine);
        //        }
        //        sb.Append("			cmd.Dispose();" + Environment.NewLine);
        //        sb.Append("			cmd = null;" + Environment.NewLine);
        //        sb.Append("			return");
        //        if (evn == "Add" && pKeyIdentity == "Y") {sb.Append(" id");}
        //        sb.Append(";" + Environment.NewLine);
        //        sb.Append("		}" + Environment.NewLine);
        //    }
        //}

        //private StringBuilder MakeAccessCs(DataRow dw, Int32 screenId, DataView dv, DataTable dtLis, DataTable dtDtl, DataView dvARule, DataView dvSRule, DataView dvCri, string appDatabase, string sysDatabase, CurrPrj CPrj, CurrSrc CSrc)
        //{
        //    DataView dvc = new DataView(dv.Table.Copy());	// For Add and Update.
        //    dvc.RowFilter = "MasterTable = 'Y' AND DisplayName not in ('HyperLink','DataGrid')";
        //    dvc.Sort = "MasterTable desc,TableOrder,TabIndex";
        //    bool firstWord = true;
        //    bool bRemove = false;
        //    string param = string.Empty;
        //    string dtype = string.Empty;
        //    string sbole = string.Empty;
        //    string dbole = string.Empty;
        //    string pMKey = string.Empty;
        //    string pMKeyColumn = string.Empty;
        //    string pMKeySByteOle = string.Empty;
        //    string pMKeySysName = string.Empty;
        //    string pMKeyIdentity = string.Empty;
        //    string pDKeyColumn = string.Empty;
        //    string pDKeySByteOle = string.Empty;
        //    string pDKeySysName = string.Empty;
        //    string pDKeyIdentity = string.Empty;
        //    //DataTable dt = null;
        //    DataTable dtCud = null;
        //    StringBuilder parameterNames = new StringBuilder();
        //    StringBuilder parameterTypes = new StringBuilder();
        //    StringBuilder parameterSByte = new StringBuilder();
        //    StringBuilder parameterDByte = new StringBuilder();
        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("using System;" + Environment.NewLine);
        //    sb.Append("using System.Text;" + Environment.NewLine);
        //    sb.Append("using System.Data;" + Environment.NewLine);
        //    sb.Append("using System.Data.OleDb;" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ";" + Environment.NewLine);
        //    sb.Append("using " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ".Data;" + Environment.NewLine);
        //    if (CSrc.SrcSystemId != 3)	// Admin.
        //    {
        //        sb.Append("using RO.Common3;" + Environment.NewLine);
        //        sb.Append("using RO.Common3.Data;" + Environment.NewLine);
        //    }
        //    sb.Append("using RO.SystemFramewk;" + Environment.NewLine);
        //    sb.Append(Environment.NewLine);
        //    sb.Append("namespace " + CPrj.EntityCode + ".Access" + CSrc.SrcSystemId.ToString() + Environment.NewLine);
        //    sb.Append("{" + Environment.NewLine);
        //    sb.Append("	public class " + dw["ProgramName"].ToString() + "Access : Encryption, IDisposable" + Environment.NewLine);
        //    sb.Append("	{" + Environment.NewLine);
        //    sb.Append("		private OleDbDataAdapter da;" + Environment.NewLine);
        //    if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {sb.Append("		private DataRowCollection rows;" + Environment.NewLine);}
        //    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) {sb.Append("		private DataRow row;" + Environment.NewLine);}
        //    sb.Append(Environment.NewLine);
        //    sb.Append("		public " + dw["ProgramName"].ToString() + "Access()" + Environment.NewLine);
        //    sb.Append("		{" + Environment.NewLine);
        //    sb.Append("			da = new OleDbDataAdapter();" + Environment.NewLine);
        //    sb.Append("		}" + Environment.NewLine);
        //    sb.Append(Environment.NewLine);
        //    sb.Append("		public void Dispose()" + Environment.NewLine);
        //    sb.Append("		{" + Environment.NewLine);
        //    sb.Append("			Dispose(true);" + Environment.NewLine);
        //    sb.Append("			GC.SuppressFinalize(true); // as a service to those who might inherit from us" + Environment.NewLine);
        //    sb.Append("		}" + Environment.NewLine);
        //    sb.Append(Environment.NewLine);
        //    sb.Append("		protected virtual void Dispose(bool disposing)" + Environment.NewLine);
        //    sb.Append("		{" + Environment.NewLine);
        //    sb.Append("			if (!disposing)" + Environment.NewLine);
        //    sb.Append("				return;" + Environment.NewLine);
        //    sb.Append(Environment.NewLine);
        //    sb.Append("			if (da != null)" + Environment.NewLine);
        //    sb.Append("			{" + Environment.NewLine);
        //    sb.Append(Environment.NewLine);
        //    sb.Append("				if(da.SelectCommand != null)" + Environment.NewLine);
        //    sb.Append("				{" + Environment.NewLine);
        //    sb.Append("					if( da.SelectCommand.Connection != null)" + Environment.NewLine);
        //    sb.Append("					{" + Environment.NewLine);
        //    sb.Append("						da.SelectCommand.Connection.Dispose();" + Environment.NewLine);
        //    sb.Append("					}" + Environment.NewLine);
        //    sb.Append("					da.SelectCommand.Dispose();" + Environment.NewLine);
        //    sb.Append("				}" + Environment.NewLine);
        //    sb.Append(Environment.NewLine);
        //    sb.Append("				if(da.InsertCommand != null)" + Environment.NewLine);
        //    sb.Append("				{" + Environment.NewLine);
        //    sb.Append("					if( da.InsertCommand.Connection != null)" + Environment.NewLine);
        //    sb.Append("					{" + Environment.NewLine);
        //    sb.Append("						da.InsertCommand.Connection.Dispose();" + Environment.NewLine);
        //    sb.Append("					}" + Environment.NewLine);
        //    sb.Append("					da.InsertCommand.Dispose();" + Environment.NewLine);
        //    sb.Append("				}" + Environment.NewLine);
        //    sb.Append(Environment.NewLine);
        //    sb.Append("				if(da.UpdateCommand != null)" + Environment.NewLine);
        //    sb.Append("				{" + Environment.NewLine);
        //    sb.Append("					if( da.UpdateCommand.Connection != null)" + Environment.NewLine);
        //    sb.Append("					{" + Environment.NewLine);
        //    sb.Append("						da.UpdateCommand.Connection.Dispose();" + Environment.NewLine);
        //    sb.Append("					}" + Environment.NewLine);
        //    sb.Append("					da.UpdateCommand.Dispose();" + Environment.NewLine);
        //    sb.Append("				}" + Environment.NewLine);
        //    sb.Append(Environment.NewLine);
        //    sb.Append("				if(da.DeleteCommand != null)" + Environment.NewLine);
        //    sb.Append("				{" + Environment.NewLine);
        //    sb.Append("					if( da.DeleteCommand.Connection != null)" + Environment.NewLine);
        //    sb.Append("					{" + Environment.NewLine);
        //    sb.Append("						da.DeleteCommand.Connection.Dispose();" + Environment.NewLine);
        //    sb.Append("					}" + Environment.NewLine);
        //    sb.Append("					da.DeleteCommand.Dispose();" + Environment.NewLine);
        //    sb.Append("				}" + Environment.NewLine);
        //    sb.Append("				da.Dispose();" + Environment.NewLine);
        //    sb.Append("				da = null;" + Environment.NewLine);
        //    sb.Append("			}" + Environment.NewLine);
        //    sb.Append("		}" + Environment.NewLine);
        //    dv.RowFilter = string.Empty;
        //    foreach (DataRowView drv in dv)
        //    {
        //        if (drv["MasterTable"].ToString() == "Y" && drv["PrimaryKey"].ToString() == "Y")
        //        {
        //            pMKey = drv["ColumnName"].ToString();
        //            pMKeyColumn = drv["ColumnName"].ToString() + drv["TableId"].ToString();
        //            pMKeySByteOle = drv["DataTypeSByteOle"].ToString();
        //            pMKeySysName = drv["DataTypeSysName"].ToString();
        //            pMKeyIdentity = drv["ColumnIdentity"].ToString();
        //        }
        //        else if (drv["MasterTable"].ToString() != "Y" && drv["PrimaryKey"].ToString() == "Y")
        //        {
        //            pDKeyColumn = drv["ColumnName"].ToString() + drv["TableId"].ToString();
        //            pDKeySByteOle = drv["DataTypeSByteOle"].ToString();
        //            pDKeySysName = drv["DataTypeSysName"].ToString();
        //            pDKeyIdentity = drv["ColumnIdentity"].ToString();
        //        }
        //    }
        //    dv.RowFilter = string.Empty;
        //    foreach (DataRowView drv in dv)
        //    {
        //        if (drv["DisplayMode"].ToString().ToLower() == "document")
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("		public string Del" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "(string MasterId, string DocId, string UsrId, string dbConnectionString, string dbPassword)" + Environment.NewLine);
        //            sb.Append("		{" + Environment.NewLine);
        //            sb.Append("			string rtn = string.Empty;" + Environment.NewLine);
        //            sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //            sb.Append("			OleDbConnection cn = new OleDbConnection(dbConnectionString + DecryptString(dbPassword)); cn.Open();" + Environment.NewLine);
        //            sb.Append("			OleDbTransaction tr = cn.BeginTransaction();" + Environment.NewLine);
        //            sb.Append("			OleDbCommand cmd = new OleDbCommand(\"SET NOCOUNT ON\"" + Environment.NewLine);
        //            sb.Append("			+ \" DECLARE @MasterId numeric(10,0), @DocId numeric(10,0), @UsrId numeric(10,0) SELECT @MasterId=?, @DocId=?, @UsrId=?\"" + Environment.NewLine);
        //            sb.Append("			+ \" IF EXISTS (SELECT 1 FROM dbo." + drv["DdlKeyTableName"].ToString() + " WHERE DocId = @DocId AND InputBy = @UsrId)\"" + Environment.NewLine);
        //            sb.Append("			+ \" BEGIN\"" + Environment.NewLine);
        //            sb.Append("				+ \" DELETE FROM dbo." + drv["DdlKeyTableName"].ToString() + " WHERE DocId = @DocId\"" + Environment.NewLine);
        //            sb.Append("				+ \" SELECT @DocId = MAX(DocId) FROM dbo." + drv["DdlKeyTableName"].ToString() + " WHERE MasterId = @MasterId\"" + Environment.NewLine);
        //            sb.Append("				+ \" UPDATE dbo." + drv["TableName"].ToString() + " SET " + drv["ColumnName"].ToString() + " = @DocId WHERE " + pMKey + " = @MasterId\"" + Environment.NewLine);
        //            sb.Append("			+ \" END\"" + Environment.NewLine);
        //            sb.Append("			+ \" SELECT @DocId\", cn);" + Environment.NewLine);
        //            sb.Append("			cmd.CommandType = CommandType.Text;" + Environment.NewLine);
        //            sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //            sb.Append("			cmd.Transaction = tr;" + Environment.NewLine);
        //            sb.Append("			cmd.Parameters.Add(\"@MasterId\", OleDbType.Numeric).Value = MasterId;" + Environment.NewLine);
        //            sb.Append("			cmd.Parameters.Add(\"@DocId\", OleDbType.Numeric).Value = DocId;" + Environment.NewLine);
        //            sb.Append("			cmd.Parameters.Add(\"@UsrId\", OleDbType.Numeric).Value = UsrId;" + Environment.NewLine);
        //            sb.Append("			da.SelectCommand = cmd;" + Environment.NewLine);
        //            sb.Append("			DataTable dt = new DataTable();" + Environment.NewLine);
        //            sb.Append("			try" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				da.Fill(dt); rtn = dt.Rows[0][0].ToString(); tr.Commit();" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			catch (Exception e)" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				tr.Rollback(); ApplicationAssert.CheckCondition(false, \"\", \"\", e.Message);" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			finally { cn.Close(); }" + Environment.NewLine);
        //            sb.Append("			return rtn;" + Environment.NewLine);
        //            sb.Append("		}" + Environment.NewLine);
        //        }
        //        //if (drv["ColumnIdentity"].ToString() != "Y" && (",ComboBox,DropDownList,ListBox,RadioButtonList,DataGrid,".IndexOf(","+drv["DisplayName"].ToString()+",") >= 0 || drv["DisplayMode"].ToString().ToLower() == "document"))
        //        //{
        //        //    using (GenScreensAccessBase dac = GetGenScreensAccess())
        //        //    {
        //        //        dt = dac.GetScreenObjDdlById(screenId, Int32.Parse(drv["ScreenObjId"].ToString()), "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString(), "N", appDatabase, sysDatabase, CPrj.SrcDesDatabase, pMKey, drv["MultiDesignDb"].ToString(), CSrc);
        //        //    }
        //        //    bRemove = false;
        //        //    dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        //    foreach (DataRowView dra in dvARule)
        //        //    {
        //        //        if (dra["RmFuncProc"].ToString() == "GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString()) { bRemove = true; break; }
        //        //    }
        //        //    if (!bRemove)
        //        //    {
        //        //        sb.Append(Environment.NewLine);
        //        //        sb.Append("		public DataTable GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "(Int32 screenId, bool bAll, int topN, ");
        //        //        parameterNames.Remove(0, parameterNames.Length);
        //        //        parameterTypes.Remove(0, parameterTypes.Length);
        //        //        parameterNames.Append(dt.Rows[0]["parameter2Names"].ToString());
        //        //        parameterTypes.Append(dt.Rows[0]["parameter2Types"].ToString());
        //        //        firstWord = true;
        //        //        while (parameterNames.Length > 0 && parameterTypes.Length > 0)
        //        //        {
        //        //            if (firstWord) { firstWord = false; } else { sb.Append(", "); }
        //        //            sb.Append(Utils.PopFirstWord(parameterTypes, (char)44) + " " + Utils.PopFirstWord(parameterNames, (char)44));
        //        //        }
        //        //        sb.Append(Robot.GetCnDclr(drv["MultiDesignDb"].ToString(), "N") + ",string filterTxt, UsrImpr ui, UsrCurr uc)" + Environment.NewLine);
        //        //        sb.Append("		{" + Environment.NewLine);
        //        //        sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //        //        sb.Append("			OleDbCommand cmd = new OleDbCommand(\"GetDdl" + drv["ColumnName"].ToString() + CSrc.SrcSystemId.ToString() + "S" + drv["ScreenObjId"].ToString() + "\",new OleDbConnection(" + Robot.GetCnPass(drv["MultiDesignDb"].ToString(), "N") + "));" + Environment.NewLine);
        //        //        sb.Append("			cmd.CommandType = CommandType.StoredProcedure;" + Environment.NewLine);
        //        //        sb.Append("			cmd.Parameters.Add(\"@screenId\", OleDbType.Numeric).Value = screenId;" + Environment.NewLine);
        //        //        sb.Append("			if (bAll) {cmd.Parameters.Add(\"@bAll\", OleDbType.Char).Value = \"Y\";} else {cmd.Parameters.Add(\"@bAll\", OleDbType.Char).Value = \"N\";}" + Environment.NewLine);
        //        //        parameterNames.Remove(0, parameterNames.Length);
        //        //        parameterSByte.Remove(0, parameterSByte.Length);
        //        //        parameterDByte.Remove(0, parameterDByte.Length);
        //        //        parameterNames.Append(dt.Rows[0]["Parameter2Names"].ToString());
        //        //        parameterSByte.Append(dt.Rows[0]["Parameter2SByte"].ToString());
        //        //        parameterDByte.Append(dt.Rows[0]["Parameter2DByte"].ToString());
        //        //        param = string.Empty; sbole = string.Empty; dbole = string.Empty;
        //        //        while (parameterNames.Length > 0)
        //        //        {
        //        //            param = Utils.PopFirstWord(parameterNames, (char)44);
        //        //            sbole = Utils.PopFirstWord(parameterSByte, (char)44);
        //        //            dbole = Utils.PopFirstWord(parameterDByte, (char)44);
        //        //            sb.Append("			if (" + param + " == string.Empty)" + Environment.NewLine);
        //        //            sb.Append("			{" + Environment.NewLine);
        //        //            sb.Append("				cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //        //            sb.Append("			}" + Environment.NewLine);
        //        //            sb.Append("			else" + Environment.NewLine);
        //        //            sb.Append("			{" + Environment.NewLine);
        //        //            sb.Append("	");
        //        //            if (sbole == dbole)
        //        //            {
        //        //                sb.Append("			cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";" + Environment.NewLine);
        //        //            }
        //        //            else
        //        //            {
        //        //                sb.Append("			if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + dbole + ").Value = " + param + ";} else {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";}" + Environment.NewLine);
        //        //            }
        //        //            sb.Append("			}" + Environment.NewLine);
        //        //        }
        //        //        parameterNames.Remove(0, parameterNames.Length);
        //        //        parameterSByte.Remove(0, parameterSByte.Length);
        //        //        parameterNames.Append(dt.Rows[0]["Parameter1Names"].ToString());
        //        //        parameterSByte.Append(dt.Rows[0]["Parameter1SByte"].ToString());
        //        //        param = string.Empty; sbole = string.Empty;
        //        //        while (parameterNames.Length > 0)
        //        //        {
        //        //            param = Utils.PopFirstWord(parameterNames, (char)44);
        //        //            sbole = Utils.PopFirstWord(parameterSByte, (char)44);
        //        //            sb.Append("			cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = ui." + param + ";" + Environment.NewLine);
        //        //        }
        //        //        sb.Append("			cmd.Parameters.Add(\"@currCompanyId\", OleDbType.Numeric).Value = uc.CompanyId;" + Environment.NewLine);
        //        //        sb.Append("			cmd.Parameters.Add(\"@currProjectId\", OleDbType.Numeric).Value = uc.ProjectId;" + Environment.NewLine);
        //        //        parameterNames.Remove(0, parameterNames.Length);
        //        //        parameterSByte.Remove(0, parameterSByte.Length);
        //        //        parameterDByte.Remove(0, parameterDByte.Length);
        //        //        parameterNames.Append(dt.Rows[0]["Parameter3Names"].ToString());
        //        //        parameterSByte.Append(dt.Rows[0]["Parameter3SByte"].ToString());
        //        //        parameterDByte.Append(dt.Rows[0]["Parameter3DByte"].ToString());
        //        //        param = string.Empty; sbole = string.Empty; dbole = string.Empty;
        //        //        while (parameterNames.Length > 0)
        //        //        {
        //        //            param = Utils.PopFirstWord(parameterNames, (char)44);
        //        //            sbole = Utils.PopFirstWord(parameterSByte, (char)44);
        //        //            dbole = Utils.PopFirstWord(parameterDByte, (char)44);
        //        //            sb.Append("			if (" + param + " == string.Empty)" + Environment.NewLine);
        //        //            sb.Append("			{" + Environment.NewLine);
        //        //            sb.Append("				cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //        //            sb.Append("			}" + Environment.NewLine);
        //        //            sb.Append("			else" + Environment.NewLine);
        //        //            sb.Append("			{" + Environment.NewLine);
        //        //            sb.Append("	");
        //        //            if (sbole == dbole)
        //        //            {
        //        //                sb.Append("			cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";" + Environment.NewLine);
        //        //            }
        //        //            else
        //        //            {
        //        //                sb.Append("			if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + dbole + ").Value = " + param + ";} else {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";}" + Environment.NewLine);
        //        //            }
        //        //            sb.Append("			}" + Environment.NewLine);
        //        //        }
        //        //        sb.Append("			cmd.Parameters.Add(\"@topN\", OleDbType.Numeric).Value = topN ;" + Environment.NewLine);
        //        //        sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //        //        sb.Append("			da.SelectCommand = cmd;" + Environment.NewLine);
        //        //        sb.Append("			DataTable dt = new DataTable();" + Environment.NewLine);
        //        //        sb.Append("			da.Fill(dt);" + Environment.NewLine);
        //        //        if (drv["DisplayName"].ToString() == "DropDownList" || (drv["AllowNulls"].ToString() == "Y" && drv["RequiredValid"].ToString() == "N" && drv["DisplayMode"].ToString() != "Document"))
        //        //        {
        //        //            sb.Append("			dt.Rows.InsertAt(dt.NewRow(),0);" + Environment.NewLine);
        //        //            if (drv["DisplayName"].ToString() == "RadioButtonList") { sb.Append("			dt.Rows[0][\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\"] = \"n/a\";" + Environment.NewLine); }
        //        //        }
        //        //        sb.Append("			return dt;" + Environment.NewLine);
        //        //        sb.Append("		}" + Environment.NewLine);
        //        //    }
        //        //}
        //    }
        //    //if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "GetExp" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("		public DataTable GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "(string useGlobalFilter, Int32 screenId");
        //    //        sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ", Int32 screenFilterId, DataView dvCri, UsrImpr ui, UsrCurr uc, DataSet ds)" + Environment.NewLine);
        //    //        sb.Append("		{" + Environment.NewLine);
        //    //        sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //    //        sb.Append("			OleDbCommand cmd = new OleDbCommand(\"GetExp" + dw["ProgramName"].ToString() + screenId.ToString() + "\",new OleDbConnection(" + Robot.GetCnPass(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + "));" + Environment.NewLine);
        //    //        sb.Append("			cmd.CommandType = CommandType.StoredProcedure;" + Environment.NewLine);
        //    //        sb.Append("			DataRow dr = ds.Tables[\"DtScreenIn\"].Rows[0];" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@useGlobalFilter\", OleDbType.VarChar).Value = useGlobalFilter;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@screenId\", OleDbType.Numeric).Value = screenId;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Usrs\", OleDbType.VarChar).Value = ui.Usrs;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@RowAuthoritys\", OleDbType.VarChar).Value = ui.RowAuthoritys;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Customers\", OleDbType.VarChar).Value = ui.Customers;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Vendors\", OleDbType.VarChar).Value = ui.Vendors;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Members\", OleDbType.VarChar).Value = ui.Members;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Investors\", OleDbType.VarChar).Value = ui.Investors;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Agents\", OleDbType.VarChar).Value = ui.Agents;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Brokers\", OleDbType.VarChar).Value = ui.Brokers;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@UsrGroups\", OleDbType.VarChar).Value = ui.UsrGroups;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Companys\", OleDbType.VarChar).Value = ui.Companys;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Projects\", OleDbType.VarChar).Value = ui.Projects;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@Cultures\", OleDbType.VarChar).Value = ui.Cultures;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@key\", OleDbType.VarWChar).Value = System.DBNull.Value;" + Environment.NewLine);
        //    //        sb.Append("			foreach (DataRowView drv in dvCri)" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("			    if (drv[\"RequiredValid\"].ToString() == \"N\" && dr[drv[\"ColumnName\"].ToString()].ToString().Trim() == string.Empty)" + Environment.NewLine);
        //    //        sb.Append("			    {" + Environment.NewLine);
        //    //        sb.Append("					if (drv[\"DataTypeSByteOle\"].ToString() == \"Numeric\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Numeric).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Single\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Single).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Double\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Double).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Currency\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Currency).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Binary\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Binary).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"VarBinary\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarBinary).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"DBTimeStamp\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.DBTimeStamp).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Decimal\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Decimal).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"DBDate\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.DBDate).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Char\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Char).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("					else { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarChar).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //        sb.Append("			    }" + Environment.NewLine);
        //    //        sb.Append("			    else if (Config.DoubleByteDb && drv[\"DataTypeDByteOle\"].ToString() == \"WChar\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.WChar).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("			    else if (Config.DoubleByteDb && drv[\"DataTypeDByteOle\"].ToString() == \"VarWChar\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarWChar).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("			    else" + Environment.NewLine);
        //    //        sb.Append("			    {" + Environment.NewLine);
        //    //        sb.Append("					if (drv[\"DataTypeSByteOle\"].ToString() == \"Numeric\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Numeric).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Single\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Single).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Double\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Double).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Currency\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Currency).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Binary\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Binary).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"VarBinary\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarBinary).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"DBTimeStamp\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.DBTimeStamp).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Decimal\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Decimal).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"DBDate\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.DBDate).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Char\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Char).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("					else { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarChar).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //        sb.Append("			    }" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@screenFilterId\", OleDbType.Numeric).Value = screenFilterId;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@currCompanyId\", OleDbType.Numeric).Value = uc.CompanyId;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@currProjectId\", OleDbType.Numeric).Value = uc.ProjectId;" + Environment.NewLine);
        //    //        sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //    //        sb.Append("			da.SelectCommand = cmd;" + Environment.NewLine);
        //    //        sb.Append("			DataTable dt = new DataTable();" + Environment.NewLine);
        //    //        sb.Append("			da.Fill(dt);" + Environment.NewLine);
        //    //        sb.Append("			return dt;" + Environment.NewLine);
        //    //        sb.Append("		}" + Environment.NewLine);
        //    //    }
        //    //}
        //    //bRemove = false;
        //    //dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //foreach (DataRowView dra in dvARule)
        //    //{
        //    //    if (dra["RmFuncProc"].ToString() == "GetLis" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    //}
        //    //if (!bRemove)
        //    //{
        //    //    sb.Append(Environment.NewLine);
        //    //    sb.Append("		public DataTable GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "(string useGlobalFilter, Int32 screenId, int topN");
        //    //    sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ", Int32 screenFilterId, string key, string filterTxt, DataView dvCri, UsrImpr ui, UsrCurr uc, DataSet ds)" + Environment.NewLine);
        //    //    sb.Append("		{" + Environment.NewLine);
        //    //    sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //    //    sb.Append("			OleDbCommand cmd = new OleDbCommand(\"GetLis" + dw["ProgramName"].ToString() + screenId.ToString() + "\",new OleDbConnection(" + Robot.GetCnPass(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + "));" + Environment.NewLine);
        //    //    sb.Append("			cmd.CommandType = CommandType.StoredProcedure;" + Environment.NewLine);
        //    //    sb.Append("			DataRow dr = ds.Tables[\"DtScreenIn\"].Rows[0];" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@useGlobalFilter\", OleDbType.VarChar).Value = useGlobalFilter;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@screenId\", OleDbType.Numeric).Value = screenId;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Usrs\", OleDbType.VarChar).Value = ui.Usrs;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@RowAuthoritys\", OleDbType.VarChar).Value = ui.RowAuthoritys;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Customers\", OleDbType.VarChar).Value = ui.Customers;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Vendors\", OleDbType.VarChar).Value = ui.Vendors;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Members\", OleDbType.VarChar).Value = ui.Members;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Investors\", OleDbType.VarChar).Value = ui.Investors;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Agents\", OleDbType.VarChar).Value = ui.Agents;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Brokers\", OleDbType.VarChar).Value = ui.Brokers;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@UsrGroups\", OleDbType.VarChar).Value = ui.UsrGroups;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Companys\", OleDbType.VarChar).Value = ui.Companys;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Projects\", OleDbType.VarChar).Value = ui.Projects;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@Cultures\", OleDbType.VarChar).Value = ui.Cultures;" + Environment.NewLine);
        //    //    sb.Append("			if (key == string.Empty) { cmd.Parameters.Add(\"@key\", OleDbType.VarWChar).Value = System.DBNull.Value; } else { cmd.Parameters.Add(\"@key\", OleDbType.VarWChar).Value = key; }" + Environment.NewLine);
        //    //    sb.Append("			if (filterTxt == string.Empty) { cmd.Parameters.Add(\"@filterTxt\", OleDbType.VarWChar).Value = System.DBNull.Value; } else { cmd.Parameters.Add(\"@filterTxt\", OleDbType.VarWChar).Value = filterTxt; }" + Environment.NewLine);
        //    //    sb.Append("			foreach (DataRowView drv in dvCri)" + Environment.NewLine);
        //    //    sb.Append("			{" + Environment.NewLine);
        //    //    sb.Append("			    if (drv[\"RequiredValid\"].ToString() == \"N\" && (dr[drv[\"ColumnName\"].ToString()].ToString().Trim() == string.Empty) || (drv[\"DisplayName\"].ToString() == \"Rating\" && dr[drv[\"ColumnName\"].ToString()].ToString() == \"0\"))" + Environment.NewLine);
        //    //    sb.Append("			    {" + Environment.NewLine);
        //    //    sb.Append("					if (drv[\"DataTypeSByteOle\"].ToString() == \"Numeric\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Numeric).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Single\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Single).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Double\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Double).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Currency\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Currency).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Binary\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Binary).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"VarBinary\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarBinary).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"DBTimeStamp\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.DBTimeStamp).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Decimal\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Decimal).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"DBDate\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.DBDate).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Char\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Char).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("					else { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarChar).Value = System.DBNull.Value; }" + Environment.NewLine);
        //    //    sb.Append("			    }" + Environment.NewLine);
        //    //    sb.Append("			    else if (Config.DoubleByteDb && drv[\"DataTypeDByteOle\"].ToString() == \"WChar\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.WChar).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("			    else if (Config.DoubleByteDb && drv[\"DataTypeDByteOle\"].ToString() == \"VarWChar\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarWChar).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("			    else" + Environment.NewLine);
        //    //    sb.Append("			    {" + Environment.NewLine);
        //    //    sb.Append("					if (drv[\"DataTypeSByteOle\"].ToString() == \"Numeric\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Numeric).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Single\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Single).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Double\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Double).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Currency\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Currency).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Binary\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Binary).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"VarBinary\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarBinary).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"DBTimeStamp\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.DBTimeStamp).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Decimal\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Decimal).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"DBDate\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.DBDate).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else if (drv[\"DataTypeSByteOle\"].ToString() == \"Char\") { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.Char).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("					else { cmd.Parameters.Add(\"@\" + drv[\"ColumnName\"].ToString(), OleDbType.VarChar).Value = dr[drv[\"ColumnName\"].ToString()]; }" + Environment.NewLine);
        //    //    sb.Append("			    }" + Environment.NewLine);
        //    //    sb.Append("			}" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@screenFilterId\", OleDbType.Numeric).Value = screenFilterId;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@currCompanyId\", OleDbType.Numeric).Value = uc.CompanyId;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@currProjectId\", OleDbType.Numeric).Value = uc.ProjectId;" + Environment.NewLine);
        //    //    sb.Append("			cmd.Parameters.Add(\"@topN\", OleDbType.Numeric).Value = topN;" + Environment.NewLine);
        //    //    sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //    //    sb.Append("			da.SelectCommand = cmd;" + Environment.NewLine);
        //    //    sb.Append("			DataTable dt = new DataTable();" + Environment.NewLine);
        //    //    sb.Append("			da.Fill(dt);" + Environment.NewLine);
        //    //    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0) { sb.Append("			dt.Rows.InsertAt(dt.NewRow(),0);" + Environment.NewLine); }
        //    //    sb.Append("			return dt;" + Environment.NewLine);
        //    //    sb.Append("		}" + Environment.NewLine);
        //    //}
        //    //if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById") { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("		public DataTable Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById(");
        //    //        parameterNames.Remove(0, parameterNames.Length);
        //    //        parameterNames.Append(dtLis.Rows[0]["Parameter2Names"].ToString());
        //    //        firstWord = true;
        //    //        while (parameterNames.Length > 0)
        //    //        {
        //    //            if (firstWord) { firstWord = false; }
        //    //            else { sb.Append(", "); }
        //    //            sb.Append("string " + Utils.PopFirstWord(parameterNames, (char)44));
        //    //        }
        //    //        sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //    //        sb.Append("		{" + Environment.NewLine);
        //    //        sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //    //        sb.Append("			OleDbCommand cmd = new OleDbCommand(\"Get" + dw["ProgramName"].ToString() + screenId.ToString() + "ById\",new OleDbConnection(" + Robot.GetCnPass(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + "));" + Environment.NewLine);
        //    //        sb.Append("			cmd.CommandType = CommandType.StoredProcedure;" + Environment.NewLine);
        //    //        parameterNames.Remove(0, parameterNames.Length);
        //    //        parameterSByte.Remove(0, parameterSByte.Length);
        //    //        parameterDByte.Remove(0, parameterDByte.Length);
        //    //        parameterNames.Append(dtLis.Rows[0]["parameter2Names"].ToString());
        //    //        parameterSByte.Append(dtLis.Rows[0]["parameter2SByte"].ToString());
        //    //        parameterDByte.Append(dtLis.Rows[0]["parameter2DByte"].ToString());
        //    //        param = string.Empty; sbole = string.Empty; dbole = string.Empty;
        //    //        while (parameterNames.Length > 0)
        //    //        {
        //    //            param = Utils.PopFirstWord(parameterNames, (char)44);
        //    //            sbole = Utils.PopFirstWord(parameterSByte, (char)44);
        //    //            dbole = Utils.PopFirstWord(parameterDByte, (char)44);
        //    //            sb.Append("			if (" + param + " == string.Empty)" + Environment.NewLine);
        //    //            sb.Append("			{" + Environment.NewLine);
        //    //            sb.Append("				cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //    //            sb.Append("			}" + Environment.NewLine);
        //    //            sb.Append("			else" + Environment.NewLine);
        //    //            sb.Append("			{" + Environment.NewLine);
        //    //            sb.Append("	");
        //    //            if (sbole == dbole)
        //    //            {
        //    //                sb.Append("			cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";" + Environment.NewLine);
        //    //            }
        //    //            else
        //    //            {
        //    //                sb.Append("			if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + dbole + ").Value = " + param + ";} else {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";}" + Environment.NewLine);
        //    //            }
        //    //            sb.Append("			}" + Environment.NewLine);
        //    //        }
        //    //        sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //    //        sb.Append("			da.SelectCommand = cmd;" + Environment.NewLine);
        //    //        sb.Append("			DataTable dt = new DataTable();" + Environment.NewLine);
        //    //        sb.Append("			da.Fill(dt);" + Environment.NewLine);
        //    //        sb.Append("			return dt;" + Environment.NewLine);
        //    //        sb.Append("		}" + Environment.NewLine);
        //    //    }
        //    //}
        //    //if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById") { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("		public DataTable Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById(Int32 screenId, ");
        //    //        parameterNames.Remove(0, parameterNames.Length);
        //    //        parameterNames.Append(dtDtl.Rows[0]["Parameter2Names"].ToString());
        //    //        firstWord = true;
        //    //        while (parameterNames.Length > 0)
        //    //        {
        //    //            if (firstWord) { firstWord = false; } else { sb.Append(", "); }
        //    //            sb.Append("string " + Utils.PopFirstWord(parameterNames, (char)44));
        //    //        }
        //    //        sb.Append(Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ", Int32 screenFilterId, UsrImpr ui, UsrCurr uc)" + Environment.NewLine);
        //    //        sb.Append("		{" + Environment.NewLine);
        //    //        sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //    //        sb.Append("			OleDbCommand cmd = new OleDbCommand(\"Get" + dw["ProgramName"].ToString() + screenId.ToString() + "DtlById\",new OleDbConnection(" + Robot.GetCnPass(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + "));" + Environment.NewLine);
        //    //        sb.Append("			cmd.CommandType = CommandType.StoredProcedure;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@screenId\", OleDbType.Numeric).Value = screenId;" + Environment.NewLine);
        //    //        parameterNames.Remove(0, parameterNames.Length);
        //    //        parameterSByte.Remove(0, parameterSByte.Length);
        //    //        parameterDByte.Remove(0, parameterDByte.Length);
        //    //        parameterNames.Append(dtDtl.Rows[0]["Parameter2Names"].ToString());
        //    //        parameterSByte.Append(dtDtl.Rows[0]["Parameter2SByte"].ToString());
        //    //        parameterDByte.Append(dtDtl.Rows[0]["Parameter2DByte"].ToString());
        //    //        param = string.Empty; sbole = string.Empty; dbole = string.Empty;
        //    //        while (parameterNames.Length > 0)
        //    //        {
        //    //            param = Utils.PopFirstWord(parameterNames, (char)44);
        //    //            sbole = Utils.PopFirstWord(parameterSByte, (char)44);
        //    //            dbole = Utils.PopFirstWord(parameterDByte, (char)44);
        //    //            sb.Append("			if (" + param + " == string.Empty)" + Environment.NewLine);
        //    //            sb.Append("			{" + Environment.NewLine);
        //    //            sb.Append("				cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //    //            sb.Append("			}" + Environment.NewLine);
        //    //            sb.Append("			else" + Environment.NewLine);
        //    //            sb.Append("			{" + Environment.NewLine);
        //    //            sb.Append("	");
        //    //            if (sbole == dbole)
        //    //            {
        //    //                sb.Append("			cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";" + Environment.NewLine);
        //    //            }
        //    //            else
        //    //            {
        //    //                sb.Append("			if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + dbole + ").Value = " + param + ";} else {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";}" + Environment.NewLine);
        //    //            }
        //    //            sb.Append("			}" + Environment.NewLine);
        //    //        }
        //    //        parameterNames.Remove(0, parameterNames.Length);
        //    //        parameterSByte.Remove(0, parameterSByte.Length);
        //    //        parameterNames.Append(dtDtl.Rows[0]["Parameter1Names"].ToString());
        //    //        parameterSByte.Append(dtDtl.Rows[0]["Parameter1SByte"].ToString());
        //    //        param = string.Empty; sbole = string.Empty;
        //    //        while (parameterNames.Length > 0)
        //    //        {
        //    //            param = Utils.PopFirstWord(parameterNames, (char)44);
        //    //            sbole = Utils.PopFirstWord(parameterSByte, (char)44);
        //    //            sb.Append("			cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = ui." + param + ";" + Environment.NewLine);
        //    //        }
        //    //        sb.Append("			cmd.Parameters.Add(\"@screenFilterId\", OleDbType.Numeric).Value = screenFilterId;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@currCompanyId\", OleDbType.Numeric).Value = uc.CompanyId;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@currProjectId\", OleDbType.Numeric).Value = uc.ProjectId;" + Environment.NewLine);
        //    //        sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //    //        sb.Append("			da.SelectCommand = cmd;" + Environment.NewLine);
        //    //        sb.Append("			DataTable dt = new DataTable();" + Environment.NewLine);
        //    //        sb.Append("			da.Fill(dt);" + Environment.NewLine);
        //    //        sb.Append("			return dt;" + Environment.NewLine);
        //    //        sb.Append("		}" + Environment.NewLine);
        //    //    }
        //    //}

        //    // dtCud.Rows[0]: Del script for master table
        //    // dtCud.Rows[1]: Add script for master table
        //    // dtCud.Rows[2]: Upd script for master table
        //    // dtCud.Rows[3]: Del script for detail table
        //    // dtCud.Rows[4]: Add script for detail table
        //    // dtCud.Rows[5]: Upd script for detail table
        //    using (GenScreensAccessBase dac = GetGenScreensAccess())
        //    {
        //        dtCud = dac.GetScreenCud(screenId, dw["ScreenTypeName"].ToString(),CPrj.SrcDesDatabase, dw["MultiDesignDb"].ToString(), CSrc);
        //    }
        //    if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //    {
        //        bRemove = false;
        //        dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Add" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //        }
        //        if (!bRemove)
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("		public string Add" + dw["ProgramName"].ToString() + screenId.ToString() + "(LoginUsr LUser, UsrImpr LImpr, UsrCurr LCurr, " + dw["ProgramName"].ToString() + screenId.ToString() + " ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //            sb.Append("		{" + Environment.NewLine);
        //            if (dw["DeferError"].ToString() == "Y")
        //            {
        //                sb.Append("			bool bHasErr = false;" + Environment.NewLine);
        //                sb.Append("			System.Collections.Generic.Dictionary<string, string> ErrLst = new System.Collections.Generic.Dictionary<string, string>();" + Environment.NewLine);
        //            }
        //            sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //            sb.Append("			OleDbConnection cn =  new OleDbConnection(" + Robot.GetCnPass(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //            sb.Append("			cn.Open();" + Environment.NewLine);
        //            sb.Append("			OleDbTransaction tr = cn.BeginTransaction();" + Environment.NewLine);
        //            sb.Append("			OleDbCommand cmd = new OleDbCommand(\"SET NOCOUNT ON\"");
        //            sb.Append(dtCud.Rows[1][0].ToString() + ", cn);" + Environment.NewLine);
        //            sb.Append("			cmd.CommandType = CommandType.Text;" + Environment.NewLine);
        //            sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //            sb.Append("			cmd.Transaction = tr;" + Environment.NewLine);
        //            sb.Append("			row = ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].Rows[0];" + Environment.NewLine);
        //            foreach (DataRowView drv in dvc)
        //            {
        //                if ((drv["TableId"].ToString() != string.Empty && (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DdlRefColumnId"].ToString() == string.Empty) && drv["SystemValue"].ToString() == string.Empty) || drv["DisplayMode"].ToString().ToLower() == "document")
        //                {
        //                    if (drv["RequiredValid"].ToString() == "N")
        //                    {
        //                        sb.Append("			if (row[\"" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\"].ToString().Trim() == string.Empty");
        //                        if (",SmallDateTime,DateTime,".IndexOf("," + drv["DataTypeSqlName"].ToString() + ",") >= 0)
        //                        {
        //                            sb.Append(" || row[\"" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\"].ToString().Trim() == Convert.ToDateTime(\"0001.01.01\").ToString()");
        //                        }
        //                        sb.Append(")" + Environment.NewLine);
        //                        sb.Append("			{" + Environment.NewLine);
        //                        sb.Append("				cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //                        sb.Append("			}" + Environment.NewLine);
        //                        sb.Append("			else" + Environment.NewLine);
        //                        sb.Append("			{" + Environment.NewLine);
        //                    }
        //                    if (drv["DataTypeSByteOle"].ToString() == drv["DataTypeDByteOle"].ToString())
        //                    {
        //                        if (",SmallDateTime,DateTime,".IndexOf("," + drv["DataTypeSqlName"].ToString() + ",") >= 0)
        //                        {
        //                            sb.Append("				if (row[\"" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\"].ToString() != string.Empty) {try {Convert.ToDateTime(row[\"" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\"]);} catch {ApplicationAssert.CheckCondition(false,\"Add" + dw["ProgramName"].ToString() + screenId.ToString() + "\", \"DateTime Error\", \"Please enter a valid date and try again.\");}}" + Environment.NewLine);
        //                        }
        //                        sb.Append("				cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = " + Robot.HashRequired(drv["DisplayMode"].ToString(), drv["ColumnName"].ToString() + drv["TableId"].ToString(), drv["TrimOnEntry"].ToString()) + ";" + Environment.NewLine);
        //                    }
        //                    else
        //                    {
        //                        sb.Append("				if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeDByteOle"].ToString() + ").Value = " + Robot.HashRequired(drv["DisplayMode"].ToString(), drv["ColumnName"].ToString() + drv["TableId"].ToString(), drv["TrimOnEntry"].ToString()) + ";} else {cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = " + Robot.HashRequired(drv["DisplayMode"].ToString(), drv["ColumnName"].ToString() + drv["TableId"].ToString(), drv["TrimOnEntry"].ToString()) + ";}" + Environment.NewLine);
        //                    }
        //                    if (drv["RequiredValid"].ToString() == "N") { sb.Append("			}" + Environment.NewLine); }
        //                }
        //            }
        //            sb.Append("			try" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            MakeRulesCsPrepRule(dw, sb, dvSRule, "Add", "Y");
        //            MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Add", "Y");
        //            if (pMKeyIdentity == "Y")
        //            {
        //                // Do not use ExecuteScalar() as Sybase may deadlock.
        //                sb.Append("				da.SelectCommand = cmd;" + Environment.NewLine);
        //                sb.Append("				DataTable dt = new DataTable();" + Environment.NewLine);
        //                sb.Append("				da.Fill(dt);" + Environment.NewLine);
        //                //sb.Append("				row[\"" + pMKeyColumn + "\"] = " + Robot.ParseRequired(pMKeySysName, true) + "dt.Rows[0][0].ToString()" + Robot.ParseRequired(pMKeySysName, false) + ";" + Environment.NewLine);
        //                sb.Append("				row[\"" + pMKeyColumn + "\"] = dt.Rows[0][0].ToString();" + Environment.NewLine);
        //            }
        //            else
        //            {
        //                sb.Append("				cmd.ExecuteNonQuery();" + Environment.NewLine);
        //            }
        //            PrepDtlSp(dw, screenId, dv, sb, "Add", pMKeyColumn, pMKeyIdentity, pDKeyColumn, pDKeyIdentity);
        //            MakeRulesCsPrepRule(dw, sb, dvSRule, "Add", "N");
        //            MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Add", "N");
        //            if (dw["DeferError"].ToString() == "Y")
        //            {
        //                sb.Append("				if (!bHasErr) {tr.Commit();}" + Environment.NewLine);
        //                sb.Append("				else" + Environment.NewLine);
        //                sb.Append("				{" + Environment.NewLine);
        //                sb.Append("					StringBuilder sb = new StringBuilder();" + Environment.NewLine);
        //                sb.Append("					foreach (string err in ErrLst.Keys) {sb.Append(\"\\n\" + err + \"|\" + ErrLst[err]);}" + Environment.NewLine);
        //                sb.Append("					throw new Exception(sb.ToString());" + Environment.NewLine);
        //                sb.Append("				}" + Environment.NewLine);
        //            }
        //            else { sb.Append("				tr.Commit();" + Environment.NewLine); }
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			catch(Exception e)" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				tr.Rollback();" + Environment.NewLine);
        //            sb.Append("				ApplicationAssert.CheckCondition(false, \"Add" + dw["ProgramName"].ToString() + screenId.ToString() + "\", \"\", e.Message);" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			finally {cn.Close();}" + Environment.NewLine);
        //            sb.Append("			if ( ds.HasErrors )" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].GetErrors()[0].ClearErrors();" + Environment.NewLine);
        //            if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //            {
        //                sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + "Add\"].GetErrors()[0].ClearErrors();" + Environment.NewLine);
        //            }
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			else" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				ds.AcceptChanges();" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			return row[\"" + pMKeyColumn + "\"].ToString();" + Environment.NewLine);
        //            sb.Append("		}" + Environment.NewLine);
        //        }
        //        bRemove = false;
        //        dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Del" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //        }
        //        if (!bRemove)
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("		public bool Del" + dw["ProgramName"].ToString() + screenId.ToString() + "(LoginUsr LUser, UsrImpr LImpr, UsrCurr LCurr, " + dw["ProgramName"].ToString() + screenId.ToString() + " ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //            sb.Append("		{" + Environment.NewLine);
        //            if (dw["DeferError"].ToString() == "Y")
        //            {
        //                sb.Append("			bool bHasErr = false;" + Environment.NewLine);
        //                sb.Append("			System.Collections.Generic.Dictionary<string, string> ErrLst = new System.Collections.Generic.Dictionary<string, string>();" + Environment.NewLine);
        //            }
        //            sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //            sb.Append("			OleDbConnection cn =  new OleDbConnection(" + Robot.GetCnPass(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //            sb.Append("			cn.Open();" + Environment.NewLine);
        //            sb.Append("			OleDbTransaction tr = cn.BeginTransaction();" + Environment.NewLine);
        //            sb.Append("			OleDbCommand cmd = new OleDbCommand(\"SET NOCOUNT ON\"");
        //            sb.Append(dtCud.Rows[0][0].ToString() + ", cn);" + Environment.NewLine);
        //            sb.Append("			cmd.CommandType = CommandType.Text;" + Environment.NewLine);
        //            sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //            sb.Append("			cmd.Transaction = tr;" + Environment.NewLine);
        //            sb.Append("			row = ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].Rows[0];" + Environment.NewLine);
        //            dv.RowFilter = "MasterTable = 'Y'";
        //            foreach (DataRowView drv in dv)
        //            {
        //                if (drv["PrimaryKey"].ToString() == "Y")
        //                {
        //                    if (drv["DataTypeSByteOle"].ToString() == drv["DataTypeDByteOle"].ToString())
        //                    {
        //                        sb.Append("			cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = row[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"];" + Environment.NewLine);
        //                    }
        //                    else
        //                    {
        //                        sb.Append("			if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = row[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"];} else {cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = row[\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"];}" + Environment.NewLine);
        //                    }
        //                    break;
        //                }
        //            }
        //            sb.Append("			try" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            MakeRulesCsPrepRule(dw, sb, dvSRule, "Del", "Y");
        //            MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Del", "Y");
        //            sb.Append("				cmd.ExecuteNonQuery();" + Environment.NewLine);
        //            MakeRulesCsPrepRule(dw, sb, dvSRule, "Del", "N");
        //            MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Del", "N");
        //            if (dw["DeferError"].ToString() == "Y")
        //            {
        //                sb.Append("				if (!bHasErr) {tr.Commit();}" + Environment.NewLine);
        //                sb.Append("				else" + Environment.NewLine);
        //                sb.Append("				{" + Environment.NewLine);
        //                sb.Append("					StringBuilder sb = new StringBuilder();" + Environment.NewLine);
        //                sb.Append("					foreach (string err in ErrLst.Keys) {sb.Append(\"\\n\" + err + \"|\" + ErrLst[err]);}" + Environment.NewLine);
        //                sb.Append("					throw new Exception(sb.ToString());" + Environment.NewLine);
        //                sb.Append("				}" + Environment.NewLine);
        //            }
        //            else { sb.Append("				tr.Commit();" + Environment.NewLine); }
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			catch(Exception e)" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				tr.Rollback();" + Environment.NewLine);
        //            sb.Append("				ApplicationAssert.CheckCondition(false, \"\", \"\", e.Message);" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			finally {cn.Close();}" + Environment.NewLine);
        //            sb.Append("			if ( ds.HasErrors )" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].GetErrors()[0].ClearErrors();" + Environment.NewLine);
        //            sb.Append("				return false;" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("			else" + Environment.NewLine);
        //            sb.Append("			{" + Environment.NewLine);
        //            sb.Append("				ds.AcceptChanges();" + Environment.NewLine);
        //            sb.Append("				return true;" + Environment.NewLine);
        //            sb.Append("			}" + Environment.NewLine);
        //            sb.Append("		}" + Environment.NewLine);
        //        }
        //    }
        //    bRemove = false;
        //    dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    foreach (DataRowView dra in dvARule)
        //    {
        //        if (dra["RmFuncProc"].ToString() == "Upd" + dw["ProgramName"].ToString() + screenId.ToString()) { bRemove = true; break; }
        //    }
        //    if (!bRemove)
        //    {
        //        sb.Append(Environment.NewLine);
        //        sb.Append("		public bool Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "(LoginUsr LUser, UsrImpr LImpr, UsrCurr LCurr, " + dw["ProgramName"].ToString() + screenId.ToString() + " ds" + Robot.GetCnDclr(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ")" + Environment.NewLine);
        //        sb.Append("		{" + Environment.NewLine);
        //        if (dw["DeferError"].ToString() == "Y")
        //        {
        //            sb.Append("			bool bHasErr = false;" + Environment.NewLine);
        //            sb.Append("			System.Collections.Generic.Dictionary<string, string> ErrLst = new System.Collections.Generic.Dictionary<string, string>();" + Environment.NewLine);
        //        }
        //        sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //        sb.Append("			OleDbConnection cn =  new OleDbConnection(" + Robot.GetCnPass(dw["MultiDesignDb"].ToString(), dw["SysProgram"].ToString()) + ");" + Environment.NewLine);
        //        sb.Append("			cn.Open();" + Environment.NewLine);
        //        sb.Append("			OleDbTransaction tr = cn.BeginTransaction();" + Environment.NewLine);
        //        if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //        {
        //            sb.Append("			OleDbCommand cmd = new OleDbCommand(\"SET NOCOUNT ON\"");
        //            sb.Append(dtCud.Rows[2][0].ToString() + ", cn);" + Environment.NewLine);
        //            sb.Append("			cmd.CommandType = CommandType.Text;" + Environment.NewLine);
        //            sb.Append("			cmd.CommandTimeout = 3600;" + Environment.NewLine);	// In case of a long save.
        //            sb.Append("			da.UpdateCommand = cmd;" + Environment.NewLine);
        //            sb.Append("			da.UpdateCommand.Transaction = tr;" + Environment.NewLine);
        //            sb.Append("			row = ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].Rows[0];" + Environment.NewLine);
        //            foreach (DataRowView drv in dvc)
        //            {
        //                if ((drv["TableId"].ToString() != string.Empty && (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 || drv["DdlRefColumnId"].ToString() == string.Empty) && drv["SystemValue"].ToString() == string.Empty) || drv["DisplayMode"].ToString().ToLower() == "document")
        //                {
        //                    if (drv["RequiredValid"].ToString() == "N")
        //                    {
        //                        sb.Append("			if (row[\"" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\"].ToString().Trim() == string.Empty");
        //                        if (",SmallDateTime,DateTime,".IndexOf("," + drv["DataTypeSqlName"].ToString() + ",") >= 0)
        //                        {
        //                            sb.Append(" || row[\"" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\"].ToString().Trim() == Convert.ToDateTime(\"0001.01.01\").ToString()");
        //                        }
        //                        sb.Append(")" + Environment.NewLine);
        //                        sb.Append("			{" + Environment.NewLine);
        //                        sb.Append("				cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //                        sb.Append("			}" + Environment.NewLine);
        //                        sb.Append("			else" + Environment.NewLine);
        //                        sb.Append("			{" + Environment.NewLine);
        //                    }
        //                    if (drv["DataTypeSByteOle"].ToString() == drv["DataTypeDByteOle"].ToString())
        //                    {
        //                        if (",SmallDateTime,DateTime,".IndexOf("," + drv["DataTypeSqlName"].ToString() + ",") >= 0)
        //                        {
        //                            sb.Append("				if (row[\"" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\"].ToString() != string.Empty) {try {Convert.ToDateTime(row[\"" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\"]);} catch {ApplicationAssert.CheckCondition(false,\"Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "\", \"DateTime Error\", \"Please enter a valid date and try again.\");}}" + Environment.NewLine);
        //                        }
        //                        sb.Append("				cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = " + Robot.HashRequired(drv["DisplayMode"].ToString(), drv["ColumnName"].ToString() + drv["TableId"].ToString(), drv["TrimOnEntry"].ToString()) + ";" + Environment.NewLine);
        //                    }
        //                    else
        //                    {
        //                        sb.Append("				if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeDByteOle"].ToString() + ").Value = " + Robot.HashRequired(drv["DisplayMode"].ToString(), drv["ColumnName"].ToString() + drv["TableId"].ToString(), drv["TrimOnEntry"].ToString()) + ";} else {cmd.Parameters.Add(\"@" + Robot.SmallCapToStart(drv["ColumnName"].ToString()) + drv["TableId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = " + Robot.HashRequired(drv["DisplayMode"].ToString(), drv["ColumnName"].ToString() + drv["TableId"].ToString(), drv["TrimOnEntry"].ToString()) + ";}" + Environment.NewLine);
        //                    }
        //                    if (drv["RequiredValid"].ToString() == "N") { sb.Append("			}" + Environment.NewLine); }
        //                }
        //            }
        //        }
        //        sb.Append("			try" + Environment.NewLine);
        //        sb.Append("			{" + Environment.NewLine);
        //        MakeRulesCsPrepRule(dw, sb, dvSRule, "Upd", "Y");
        //        MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Add", "Y");
        //        MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Upd", "Y");
        //        MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Del", "Y");
        //        if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //        {
        //            sb.Append("				da.UpdateCommand.ExecuteNonQuery();" + Environment.NewLine);
        //        }
        //        PrepDtlSp(dw, screenId, dv, sb, "Del", pMKeyColumn, pMKeyIdentity, pDKeyColumn, pDKeyIdentity);
        //        PrepDtlSp(dw, screenId, dv, sb, "Add", pMKeyColumn, pMKeyIdentity, pDKeyColumn, pDKeyIdentity);
        //        PrepDtlSp(dw, screenId, dv, sb, "Upd", pMKeyColumn, pMKeyIdentity, pDKeyColumn, pDKeyIdentity);
        //        MakeRulesCsPrepRule(dw, sb, dvSRule, "Upd", "N");
        //        MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Add", "N");
        //        MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Upd", "N");
        //        MakeRulesCsPrepDtlRule(dw, sb, dvSRule, "Del", "N");
        //        if (dw["DeferError"].ToString() == "Y")
        //        {
        //            sb.Append("				if (!bHasErr) {tr.Commit();}" + Environment.NewLine);
        //            sb.Append("				else" + Environment.NewLine);
        //            sb.Append("				{" + Environment.NewLine);
        //            sb.Append("					StringBuilder sb = new StringBuilder();" + Environment.NewLine);
        //            sb.Append("					foreach (string err in ErrLst.Keys) {sb.Append(\"\\n\" + err + \"|\" + ErrLst[err]);}" + Environment.NewLine);
        //            sb.Append("					throw new Exception(sb.ToString());" + Environment.NewLine);
        //            sb.Append("				}" + Environment.NewLine);
        //        }
        //        else { sb.Append("				tr.Commit();" + Environment.NewLine); }
        //        sb.Append("			}" + Environment.NewLine);
        //        sb.Append("			catch(Exception e)" + Environment.NewLine);
        //        sb.Append("			{" + Environment.NewLine);
        //        sb.Append("				tr.Rollback();" + Environment.NewLine);
        //        sb.Append("				ApplicationAssert.CheckCondition(false, \"Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "\", \"\", e.Message);" + Environment.NewLine);
        //        sb.Append("			}" + Environment.NewLine);
        //        sb.Append("			finally {cn.Close();}" + Environment.NewLine);
        //        sb.Append("			if ( ds.HasErrors )" + Environment.NewLine);
        //        sb.Append("			{" + Environment.NewLine);
        //        if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //        {
        //            sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + "\"].GetErrors()[0].ClearErrors();" + Environment.NewLine);
        //        }
        //        if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
        //        {
        //            sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + "Add\"].GetErrors()[0].ClearErrors();" + Environment.NewLine);
        //            sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + "Upd\"].GetErrors()[0].ClearErrors();" + Environment.NewLine);
        //            sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + "Del\"].GetErrors()[0].ClearErrors();" + Environment.NewLine);
        //        }
        //        sb.Append("				return false;" + Environment.NewLine);
        //        sb.Append("			}" + Environment.NewLine);
        //        sb.Append("			else" + Environment.NewLine);
        //        sb.Append("			{" + Environment.NewLine);
        //        sb.Append("				ds.AcceptChanges();" + Environment.NewLine);
        //        sb.Append("				return true;" + Environment.NewLine);
        //        sb.Append("			}" + Environment.NewLine);
        //        sb.Append("		}" + Environment.NewLine);
        //        bRemove = false;
        //        dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Del" + dw["ProgramName"].ToString() + screenId.ToString() + "Dt") { bRemove = true; break; }
        //        }
        //        if (!bRemove) { MakeDtlSp(dw, screenId, dv, sb, "Del", pMKeyColumn, pMKeySByteOle, pMKeySysName, pMKeyIdentity, pDKeyColumn, pDKeySByteOle, pDKeySysName, pDKeyIdentity, dtCud); }
        //        bRemove = false;
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Add" + dw["ProgramName"].ToString() + screenId.ToString() + "Dt") { bRemove = true; break; }
        //        }
        //        if (!bRemove) { MakeDtlSp(dw, screenId, dv, sb, "Add", pMKeyColumn, pMKeySByteOle, pMKeySysName, pMKeyIdentity, pDKeyColumn, pDKeySByteOle, pDKeySysName, pDKeyIdentity, dtCud); }
        //        bRemove = false;
        //        foreach (DataRowView dra in dvARule)
        //        {
        //            if (dra["RmFuncProc"].ToString() == "Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "Dt") { bRemove = true; break; }
        //        }
        //        if (!bRemove) { MakeDtlSp(dw, screenId, dv, sb, "Upd", pMKeyColumn, pMKeySByteOle, pMKeySysName, pMKeyIdentity, pDKeyColumn, pDKeySByteOle, pDKeySysName, pDKeyIdentity, dtCud); }
        //        dvSRule.RowFilter = string.Empty;
        //        foreach (DataRowView drv in dvSRule)
        //        {
        //            sb.Append(Environment.NewLine);
        //            sb.Append("		protected void " + drv["ProcedureName"].ToString() + "(");
        //            parameterNames.Remove(0, parameterNames.Length);
        //            parameterNames.Append(drv["ParameterNames"].ToString());
        //            firstWord = true;
        //            while (parameterNames.Length > 0)
        //            {
        //                if (firstWord) { firstWord = false; } else { sb.Append(", "); }
        //                sb.Append("string " + Utils.PopFirstWord(parameterNames, (char)44));
        //            }
        //            if (!firstWord) { sb.Append(", "); }
        //            sb.Append("OleDbConnection cn, OleDbTransaction tr)" + Environment.NewLine);
        //            sb.Append("		{" + Environment.NewLine);
        //            sb.Append("			OleDbCommand cmd = new OleDbCommand(\"" + drv["ProcedureName"].ToString() + "\", cn);" + Environment.NewLine);
        //            sb.Append("			cmd.CommandType = CommandType.StoredProcedure;" + Environment.NewLine);
        //            parameterNames.Remove(0, parameterNames.Length);
        //            parameterTypes.Remove(0, parameterTypes.Length);
        //            parameterNames.Append(drv["ParameterNames"].ToString());
        //            parameterTypes.Append(drv["ParameterTypes"].ToString());
        //            param = string.Empty; dtype = string.Empty; sbole = string.Empty; dbole = string.Empty;
        //            while (parameterNames.Length > 0)
        //            {
        //                param = Utils.PopFirstWord(parameterNames, (char)44);
        //                dtype = Utils.PopFirstWord(parameterTypes, (char)44);
        //                using (GenScreensAccessBase dac = GetGenScreensAccess()) { sbole = dac.GetSByteOle(dtype, CPrj); dbole = dac.GetDByteOle(dtype, CPrj); }
        //                sb.Append("			if (" + param + " == string.Empty)" + Environment.NewLine);
        //                sb.Append("			{" + Environment.NewLine);
        //                sb.Append("				cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //                sb.Append("			}" + Environment.NewLine);
        //                sb.Append("			else" + Environment.NewLine);
        //                sb.Append("			{" + Environment.NewLine);
        //                sb.Append("	");
        //                if (sbole == dbole)
        //                {
        //                    sb.Append("			cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";" + Environment.NewLine);
        //                }
        //                else
        //                {
        //                    sb.Append("			if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + dbole + ").Value = " + param + ";} else {cmd.Parameters.Add(\"@" + param + "\", OleDbType." + sbole + ").Value = " + param + ";}" + Environment.NewLine);
        //                }
        //                sb.Append("			}" + Environment.NewLine);
        //            }
        //            sb.Append("			cmd.Transaction = tr;" + Environment.NewLine);
        //            sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //            sb.Append("			cmd.ExecuteNonQuery();" + Environment.NewLine);
        //            sb.Append("			cmd.Dispose();" + Environment.NewLine);
        //            sb.Append("			cmd = null;" + Environment.NewLine);
        //            sb.Append("			return;" + Environment.NewLine);
        //            sb.Append("		}" + Environment.NewLine);
        //        }
        //    }
        //    //if (dvCri.Count > 0)
        //    //{
        //    //    bRemove = false;
        //    //    dvARule.RowFilter = "RuleLayerCd = 'A' AND RmFuncProc is not null AND RmFuncProc <> ''";
        //    //    foreach (DataRowView dra in dvARule)
        //    //    {
        //    //        if (dra["RmFuncProc"].ToString() == "Upd" + dw["ProgramName"].ToString() + "In") { bRemove = true; break; }
        //    //    }
        //    //    if (!bRemove)
        //    //    {
        //    //        sb.Append(Environment.NewLine);
        //    //        sb.Append("		public bool Upd" + dw["ProgramName"].ToString() + "In(Int32 screenId, Int32 usrId, bool isCriVisible, " + dw["ProgramName"].ToString() + screenId.ToString() + "In ds" + Robot.GetCnDclr("N", "N") + ")" + Environment.NewLine);
        //    //        sb.Append("		{" + Environment.NewLine);
        //    //        sb.Append("			if (da == null) {throw new System.ObjectDisposedException( GetType().FullName );}" + Environment.NewLine);
        //    //        sb.Append("			OleDbConnection cn =  new OleDbConnection(" + Robot.GetCnPass("N", "N") + ");" + Environment.NewLine);
        //    //        sb.Append("			cn.Open();" + Environment.NewLine);
        //    //        sb.Append("			OleDbTransaction tr = cn.BeginTransaction();" + Environment.NewLine);
        //    //        sb.Append("			OleDbCommand cmd = new OleDbCommand(\"Upd" + dw["ProgramName"].ToString() + screenId.ToString() + "In\", cn);" + Environment.NewLine);
        //    //        sb.Append("			cmd.CommandType = CommandType.StoredProcedure;" + Environment.NewLine);
        //    //        sb.Append("			cmd.CommandTimeout = 1800;" + Environment.NewLine);
        //    //        sb.Append("			da.UpdateCommand = cmd;" + Environment.NewLine);
        //    //        sb.Append("			da.UpdateCommand.Transaction = tr;" + Environment.NewLine);
        //    //        sb.Append("			DataRow dr = ds.Tables[\"" + dw["ProgramName"].ToString() + screenId.ToString() + "In\"].Rows[0];" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@screenId\", OleDbType.Numeric).Value = screenId;" + Environment.NewLine);
        //    //        sb.Append("			cmd.Parameters.Add(\"@usrId\", OleDbType.Numeric).Value = usrId;" + Environment.NewLine);
        //    //        sb.Append("			if (isCriVisible) {cmd.Parameters.Add(\"@isCriVisible\", OleDbType.Char).Value = \"Y\";} else {cmd.Parameters.Add(\"@isCriVisible\", OleDbType.Char).Value = \"N\";}" + Environment.NewLine);
        //    //        foreach (DataRowView drv in dvCri)
        //    //        {
        //    //            if (",Button,ImageButton,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0)
        //    //            {
        //    //                if (drv["RequiredValid"].ToString() == "N")
        //    //                {
        //    //                    sb.Append("			if (dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"].ToString() == string.Empty)" + Environment.NewLine);
        //    //                    sb.Append("			{" + Environment.NewLine);
        //    //                    sb.Append("				cmd.Parameters.Add(\"@" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = System.DBNull.Value;" + Environment.NewLine);
        //    //                    sb.Append("			}" + Environment.NewLine);
        //    //                    sb.Append("			else" + Environment.NewLine);
        //    //                    sb.Append("			{" + Environment.NewLine);
        //    //                    sb.Append("	");
        //    //                }
        //    //                if (drv["DataTypeSByteOle"].ToString() == drv["DataTypeDByteOle"].ToString())
        //    //                {
        //    //                    sb.Append("			cmd.Parameters.Add(\"@" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"];" + Environment.NewLine);
        //    //                }
        //    //                else
        //    //                {
        //    //                    sb.Append("			if (Config.DoubleByteDb) {cmd.Parameters.Add(\"@" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\", OleDbType." + drv["DataTypeDByteOle"].ToString() + ").Value = dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"];} else {cmd.Parameters.Add(\"@" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\", OleDbType." + drv["DataTypeSByteOle"].ToString() + ").Value = dr[\"" + drv["ColumnName"].ToString() + drv["ScreenCriId"].ToString() + "\"];}" + Environment.NewLine);
        //    //                }
        //    //                if (drv["RequiredValid"].ToString() == "N") { sb.Append("			}" + Environment.NewLine); }
        //    //            }
        //    //        }
        //    //        sb.Append("			try" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("				da.UpdateCommand.ExecuteNonQuery();" + Environment.NewLine);
        //    //        sb.Append("				tr.Commit();" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("			catch(Exception e)" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("				tr.Rollback();" + Environment.NewLine);
        //    //        sb.Append("				ApplicationAssert.CheckCondition(false, \"\", \"\", e.Message);" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("			finally" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("				cn.Close();" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("			if ( ds.HasErrors )" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("				ds.Tables[\"" + dw["ProgramName"].ToString() + screenId.ToString() + "In\"].GetErrors()[0].ClearErrors();" + Environment.NewLine);
        //    //        sb.Append("				return false;" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("			else" + Environment.NewLine);
        //    //        sb.Append("			{" + Environment.NewLine);
        //    //        sb.Append("				ds.AcceptChanges();" + Environment.NewLine);
        //    //        sb.Append("				return true;" + Environment.NewLine);
        //    //        sb.Append("			}" + Environment.NewLine);
        //    //        sb.Append("		}" + Environment.NewLine);
        //    //    }
        //    //}
        //    dvARule.RowFilter = "RuleLayerCd = 'A'";
        //    foreach (DataRowView dra in dvARule)
        //    {
        //        sb.Append(Environment.NewLine);
        //        sb.Append("		//AdvRule: " + dra["RuleName"].ToString() + Environment.NewLine);
        //        sb.Append("		" + dra["AdvRuleProg"].ToString() + Environment.NewLine);
        //        sb.Append("		// *** AdvRule End *** //" + Environment.NewLine);
        //    }
        //    sb.Append("	}" + Environment.NewLine);
        //    sb.Append("}" + Environment.NewLine);
        //    return sb;
        //}

		private void MakeDataCs(DataRow dw, Int32 screenId, DataView dv, StringBuilder sb, string pMKeyColumn, CurrPrj CPrj, CurrSrc CSrc)
		{
			sb.Append(Environment.NewLine);
			sb.Append("namespace " + CPrj.EntityCode + ".Common" + CSrc.SrcSystemId.ToString() + ".Data" + Environment.NewLine);
			sb.Append("{" + Environment.NewLine);
			//sb.Append("	[SerializableAttribute]" + Environment.NewLine);
			sb.Append("	public class " + dw["ProgramName"].ToString() + screenId.ToString() + " : DataSet" + Environment.NewLine);
			sb.Append("	{" + Environment.NewLine);
            //sb.Append("		public " + dw["ProgramName"].ToString() + screenId.ToString() + "(SerializationInfo info, StreamingContext context) : base(info, context)" + Environment.NewLine);
            //sb.Append("		{" + Environment.NewLine);
            //sb.Append("		}" + Environment.NewLine);
            //sb.Append(Environment.NewLine);
			sb.Append("		public " + dw["ProgramName"].ToString() + screenId.ToString() + "()" + Environment.NewLine);
			sb.Append("		{" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append("			this.Tables.Add(MakeColumns(new DataTable(\"" + dw["ProgramName"].ToString() + "\")));" + Environment.NewLine);
			}
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
                sb.Append("			this.Tables.Add(MakeDtlColumns(new DataTable(\"" + dw["ProgramName"].ToString() + "Def\")));" + Environment.NewLine);
                sb.Append("			this.Tables.Add(MakeDtlColumns(new DataTable(\"" + dw["ProgramName"].ToString() + "Add\")));" + Environment.NewLine);
				sb.Append("			this.Tables.Add(MakeDtlColumns(new DataTable(\"" + dw["ProgramName"].ToString() + "Upd\")));" + Environment.NewLine);
				sb.Append("			this.Tables.Add(MakeDtlColumns(new DataTable(\"" + dw["ProgramName"].ToString() + "Del\")));" + Environment.NewLine);
			}
			sb.Append("			this.DataSetName = \"" + dw["ProgramName"].ToString() + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("			this.Namespace = \"http://Rintagi.com/DataSet/" + dw["ProgramName"].ToString() + screenId.ToString() + "\";" + Environment.NewLine);
			sb.Append("		}" + Environment.NewLine);
			if ("I1,I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append(Environment.NewLine);
				sb.Append("		private DataTable MakeColumns(DataTable dt)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			DataColumnCollection columns = dt.Columns;" + Environment.NewLine);
				dv.RowFilter = "MasterTable = 'Y'";
				foreach (DataRowView drv in dv)
				{
					// Do not check 'drv["TableId"].ToString() != string.Empty' to allow for non-database columns.
                    if ((
                            (",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 
                            || drv["DdlRefColumnId"].ToString() == string.Empty 
                            || drv["DisplayMode"].ToString().ToLower() == "currency")
                        /* default always doesn't mean the front end value cannot be passed on, useful for server rule logic
                        && 
                        (drv["SystemValue"].ToString() == string.Empty 
                        || drv["DefAlways"].ToString() != "Y" 
                        )
                         */
                        /* still has client side field even for imagebutton/varbinary, useful for server rule(and make it consistent with grid treatment
                        && 
                        (drv["DisplayName"].ToString().ToLower() != "imagebutton" 
                        || drv["DataTypeSqlName"].ToString().ToLower() != "varbinary")
                         */
                        ) 
                        || drv["DisplayMode"].ToString().ToLower() == "document")
                    {
                        sb.Append("			columns.Add(\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\", " + (drv["DataTypeSqlName"].ToString().ToLower() == "varbinary" ? "typeof(object)" : "typeof(string)") + ");" + Environment.NewLine);
					}
				}
				sb.Append("			return dt;" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
			}
			if ("I2,I3".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
			{
				sb.Append(Environment.NewLine);
				sb.Append("		private DataTable MakeDtlColumns(DataTable dt)" + Environment.NewLine);
				sb.Append("		{" + Environment.NewLine);
				sb.Append("			DataColumnCollection columns = dt.Columns;" + Environment.NewLine);
				if ("I2".IndexOf(dw["ScreenTypeName"].ToString()) >= 0)
				{
					sb.Append("			columns.Add(\"" + pMKeyColumn + "\", typeof(string));" + Environment.NewLine);
					dv.RowFilter = "MasterTable <> 'Y'";
				}
				else  {dv.RowFilter = "MasterTable = 'Y'";}
				foreach (DataRowView drv in dv)
				{
					// Do not check 'drv["TableId"].ToString() != string.Empty' to allow for non-database columns.
                    if (((",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0 
                            || drv["DdlRefColumnId"].ToString() == string.Empty 
                            || drv["DisplayMode"].ToString().ToLower() == "currency") 
                            /* default always doesn't mean the front end value cannot be passed on, useful for server rule logic
                        && (drv["SystemValue"].ToString() == string.Empty
                            || drv["DefAlways"].ToString() != "Y"
                            )
                             */
                        ) 
                        || drv["DisplayMode"].ToString().ToLower() == "document")
                    {
                        sb.Append("			columns.Add(\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\", " + (drv["DataTypeSqlName"].ToString().ToLower() == "varbinary" ? "typeof(object)" : "typeof(string)") + ");" + Environment.NewLine);
					}
				}
				sb.Append("			return dt;" + Environment.NewLine);
				sb.Append("		}" + Environment.NewLine);
			}
			sb.Append("	}" + Environment.NewLine);
			sb.Append("}" + Environment.NewLine);
		}

		// The following three procedures are called for I1 & I2 only.
		private void MakeObjGrp(ref StringBuilder sb, DataView dv, DataView dvGroupCol, string sIndent, string sTabFolderId, string clientFrwork)
		{
            dv.RowFilter = "MasterTable = 'Y' AND TabFolderId = " + sTabFolderId;
            string sGrpRow = string.Empty;
            string sGrpCol = string.Empty;
            int ii = 0;
            foreach (DataRowView drv in dv)
            {
                if ((drv["ColCssClass"].ToString() != sGrpCol && sGrpCol.EndsWith("-12")) || (drv["NewGroupRow"].ToString() == "Y" && ii > 0)) { sGrpRow = "dummy"; }  // break into another row.
                if (drv["RowCssClass"].ToString() != sGrpRow)
                {
                    if (!string.IsNullOrEmpty(sGrpRow))
                    {
                        if (!string.IsNullOrEmpty(sGrpCol)) { sb.Append(sIndent + "</div></div></div>" + Environment.NewLine); }
                        sb.Append(sIndent + "</div></div>" + Environment.NewLine);
                    }
                    sb.Append(sIndent + "<div class=\"r-table " + drv["RowCssClass"].ToString() + "\"><div class=\"r-tr\">" + Environment.NewLine);
                    sGrpRow = drv["RowCssClass"].ToString();
                    sGrpCol = string.Empty;
                }
                if (drv["ColCssClass"].ToString() != sGrpCol)
                {
                    if (!string.IsNullOrEmpty(sGrpCol)) { sb.Append(sIndent + "</div></div></div>" + Environment.NewLine); }
                    sb.Append(sIndent + "<div class=\"r-td " + drv["ColCssClass"].ToString() + "\"><div class=\"screen-tabfolder\" runat=\"server\"><div class=\"r-table\">" + Environment.NewLine);
                    sGrpCol = drv["ColCssClass"].ToString();
                }
                sb.Append(sIndent + (char)9 + "<div class=\"r-tr\">" + Environment.NewLine);
                if (drv["LabelVertical"].ToString() == "Y")
                {
                    sb.Append(sIndent + (char)9 + (char)9 + "<div class=\"r-td\"></div>" + Environment.NewLine);
                    if (!MakeObjGrpLab(ref sb, drv, sIndent + (char)9 + (char)9, true))
                    {
                        sb.Append(sIndent + (char)9 + "</div>" + Environment.NewLine);
                        sb.Append(sIndent + (char)9 + "<div class=\"r-tr\">" + Environment.NewLine);
                        sb.Append(sIndent + (char)9 + (char)9 + "<div class=\"r-td\"></div>" + Environment.NewLine);
                        MakeObjGrpInp(ref sb, drv, sIndent + (char)9 + (char)9, false, clientFrwork);
                    }
                }
                else
                {
                    if (!MakeObjGrpLab(ref sb, drv, sIndent + (char)9 + (char)9, false))
                    {
                        MakeObjGrpInp(ref sb, drv, sIndent + (char)9 + (char)9, false, clientFrwork);
                    }
                }
                sb.Append(sIndent + (char)9 + "</div>" + Environment.NewLine);
                ii = ii + 1;
            }
            if (!string.IsNullOrEmpty(sGrpCol)) { sb.Append(sIndent + "</div></div></div>" + Environment.NewLine); }
            if (!string.IsNullOrEmpty(sGrpRow)) { sb.Append(sIndent + "</div></div>" + Environment.NewLine); }
            dv.RowFilter = string.Empty;
		}

		private bool MakeObjGrpLab(ref StringBuilder sb, DataRowView drv, string sIndent, bool bLabelVertical)
		{
            if (drv["DisplayName"].ToString() == "PlaceHolder")
            {
                sb.Append(sIndent + "<asp:PlaceHolder id=\"c" + Robot.GetControlName(drv) + "\" runat=\"server\" />" + Environment.NewLine);
                return true;
            }
            else if (drv["DisplayName"].ToString() == "Label")
            {
                sb.Append(sIndent + "<div class=\"r-td\"></div>" + Environment.NewLine);
                return false;
            }
            else
            {
                string halign = bLabelVertical ? "r-td r-labelL r-labelT" : "r-td r-labelR";
                sb.Append(sIndent + "<div id=\"c" + Robot.GetControlName(drv) + "P1\"");
                string sLabelCss = drv["LabelCss"].ToString();
                if (string.IsNullOrEmpty(sLabelCss))
                {
                    sb.Append(" class=\"" + halign + "\"");
                }
                else if (sLabelCss.StartsWith(".")) { sb.Append(" class=\"" + halign + " " + sLabelCss.Substring(1) + "\""); }
                else
                {
                    sb.Append(" class=\"" + halign + "\" style=\"" + sLabelCss + "\"");
                }
                sb.Append(" runat=\"server\"><asp:Label id=\"c" + Robot.GetControlName(drv) + "Label\" CssClass=\"inp-lbl\" runat=\"server\" /></div>" + Environment.NewLine);
                return false;
            }
		}

		private void MakeObjGrpInp(ref StringBuilder sb, DataRowView drv, string sIndent, bool bLabelVertical, string clientFrwork)
		{
			string cName = Robot.GetControlName(drv);
			sb.Append(sIndent + "<div id=\"c" + cName + "P2\"");
			string sContentCss = drv["ContentCss"].ToString();
            if (string.IsNullOrEmpty(sContentCss))
            {
                sb.Append(" class=\"r-td r-content\"");
            }
            else if (sContentCss.StartsWith(".")) { sb.Append(" class=\"r-td r-content " + sContentCss.Substring(1) + "\""); }
            else
            {
                sb.Append(" class=\"r-td r-content\" style=\"" + sContentCss + "\"");
            }
			sb.Append(" runat=\"server\">");
            if (drv["DisplayName"].ToString().ToLower() == "radiobuttonlist")
            {
                sb.Append(sIndent + "<div><asp:RadioButtonList id=\"c" + cName + "\" class=\"inp-rad\" RepeatDirection=\"Horizontal\" DataValueField=\"" + cName + "\" DataTextField=\"" + cName + "Text\"");
                if ((drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y") && drv["ColumnIdentity"].ToString() != "Y")
                {
                    sb.Append(" AutoPostBack=\"true\" OnSelectedIndexChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectedIndexChanged\"");
                }
                sb.Append(" runat=\"server\" />");
                if (drv["RequiredValid"].ToString() == "Y")
                {
                    sb.Append("<asp:RequiredFieldValidator id=\"cRFV" + cName + "\" ControlToValidate=\"c" + cName + "\" display=\"none\" runat=\"server\" />");
                }
                sb.Append("</div>");
                if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                {
                    sb.Append("<asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search\" CssClass=\"r-icon\" onclick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Click\" runat=\"server\" ImageUrl=\"~/Images/");
                    if (drv["ColumnLink"].ToString().ToLower().IndexOf("upload") >= 0) { sb.Append("UpLoad.png\""); } else { sb.Append("Link.gif\""); }
                    sb.Append(" CausesValidation=\"true\" />");
                }
            }
            else if (drv["DisplayMode"].ToString().ToLower() == "document")
            {
                sb.Append(Environment.NewLine);
                sb.Append(sIndent + "<asp:Panel id=\"c" + cName + "Pan\" CssClass=\"DocPanel\" Visible=\"false\" runat=\"server\">" + Environment.NewLine);
                sb.Append(sIndent + "<div>" + Environment.NewLine);
                sb.Append(sIndent + "	<div style=\"text-align:center; padding-top:24px;\"><asp:FileUpload id=\"c" + cName + "Fi\" runat=\"server\" width=\"100%\"/></div>" + Environment.NewLine);
                sb.Append(sIndent + "	<div style=\" padding:2px 0px 0 0px; text-align:center;\">" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:Button id=\"c" + cName + "Upl\" CssClass=\"small blue button DocUpload\" style=\"float:right;\" OnClientClick='NoConfirm()' onclick=\"c" + cName + "Upl_Click\" text=\"Upload\" runat=\"server\" />" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:CheckBox id=\"c" + cName + "Ow\" CssClass=\"inp-chk\" style=\"float:left;\" Text=\"Overwrite\" runat=\"server\" />  " + Environment.NewLine);
                sb.Append(sIndent + "	</div>" + Environment.NewLine);
                sb.Append(sIndent + "</div>" + Environment.NewLine);
                sb.Append(sIndent + "</asp:Panel>" + Environment.NewLine);
                sb.Append(sIndent + "<asp:Panel id=\"c" + cName + "Div\" CssClass=\"DocPanel\" style=\"overflow-x:auto; overflow-y:hidden;\" runat=\"server\">" + Environment.NewLine);
                sb.Append(sIndent + "<asp:GridView id=\"c" + cName + "GV\" CssClass=\"GrdTxt\" style=\"white-space:normal\" PagerStyle-CssClass=\"pgr\" ShowHeader=\"false\" ShowFooter=\"false\" PagerSettings-Mode=\"NumericFirstLast\" AllowPaging=\"true\" EnableViewState=\"true\" OnPageIndexChanging=\"c" + cName + "GV_PageIndexChanged\" OnRowCommand=\"c" + cName + "GV_RowCommand\" AutoGenerateColumns=\"false\" AutoGenerateEditButton=\"false\" AutoGenerateSelectButton=\"false\" runat=\"server\">" + Environment.NewLine);
                sb.Append(sIndent + "<EmptyDataTemplate>No document has been uploaded.</EmptyDataTemplate>" + Environment.NewLine);
                sb.Append(sIndent + "<Columns>" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:TemplateField><ItemTemplate><asp:Hyperlink text='<%# DataBinder.Eval(Container.DataItem,\"DocName\").ToString() %>' NavigateUrl='<%# RO.Common3.Utils.AddTilde(GetUrlWithQSHash(DataBinder.Eval(Container.DataItem,\"DocLink\").ToString()+\"&inline=Y\")) %>' CssClass=\"GrdNwrLn\" Style=\"cursor:pointer;\" target=\"_blank\" runat=\"server\" /></ItemTemplate></asp:TemplateField>" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:TemplateField><ItemTemplate><asp:Label text='<%# DataBinder.Eval(Container.DataItem,\"InputOn\").ToString() %>' CssClass=\"GrdNwrLb\" runat=\"server\" /></ItemTemplate></asp:TemplateField>" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:TemplateField><ItemTemplate><asp:Label text='<%# DataBinder.Eval(Container.DataItem,\"DocSize\").ToString() %>' CssClass=\"GrdNwrLb\" runat=\"server\" /></ItemTemplate></asp:TemplateField>" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:TemplateField><ItemTemplate><asp:Label text='<%# DataBinder.Eval(Container.DataItem,\"LoginName\").ToString() %>' CssClass=\"GrdNwrLb\" runat=\"server\" /></ItemTemplate></asp:TemplateField>" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:TemplateField><ItemTemplate><asp:Hyperlink NavigateUrl='<%# RO.Common3.Utils.AddTilde(GetUrlWithQSHash(DataBinder.Eval(Container.DataItem,\"DocLink\").ToString())) %>' CssClass=\"DocDownload\" runat=\"server\" /></ItemTemplate></asp:TemplateField>" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:TemplateField><ItemTemplate><asp:ImageButton ImageUrl=\"~/Images/Btrash.gif\" CommandName=\"deleterow\" CommandArgument='<%# DataBinder.Eval(Container.DataItem,\"DocId\").ToString() %>' OnClientClick=\"if (ConfirmPrompt(this,'Are you sure?')) NoConfirm(); else return false;\" runat=\"server\" /></ItemTemplate></asp:TemplateField>" + Environment.NewLine);
                sb.Append(sIndent + "</Columns>" + Environment.NewLine);
                sb.Append(sIndent + "</asp:GridView></asp:Panel>" + Environment.NewLine);
                sb.Append(sIndent + "<asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo\" CssClass=\"r-docIcon\" onclick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo_Click\" runat=\"server\" ImageUrl=\"~/Images/UpLoad.png\" CausesValidation=\"true\" ToolTip=\"Click to upload a document.\" />");
            }
            else if (drv["DisplayMode"].ToString().ToLower() == "upload")
            {
                sb.Append(Environment.NewLine);
                sb.Append(sIndent + "	<asp:Panel id=\"c" + cName + "Pan\" CssClass=\"DocPanel\" Visible=\"false\" runat=\"server\">" + Environment.NewLine);
                sb.Append(sIndent + "	<table width=\"100%\"><tr>" + Environment.NewLine);
                sb.Append(sIndent + "	<td style=\"display:none;\"><asp:Button id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Upl\" CssClass=\"small blue button\" OnClientClick='NoConfirm()' onclick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Upl_Click\" text=\"Upload\" runat=\"server\" /></td>" + Environment.NewLine);
                sb.Append(sIndent + "	<td><asp:FileUpload id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Fi\" runat=\"server\" onchange=\"AutoUpload(this,event);\" /></td>" + Environment.NewLine);
                sb.Append(sIndent + "	</tr></table>" + Environment.NewLine);
                sb.Append(sIndent + "	</asp:Panel>" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:TextBox id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" CssClass=\"inp-txt\" MaxLength=\"100\" AutoPostBack=\"true\"");
                if ((drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y") && drv["ColumnIdentity"].ToString() != "Y")
                {
                    sb.Append(" OnTextChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged\"");
                }
                sb.Append(" runat=\"server\" />" + Environment.NewLine);
                sb.Append(sIndent + "	<asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo\" CssClass=\"r-icon\" OnClientClick='NoConfirm()' onclick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo_Click\" runat=\"server\" ImageUrl=\"~/Images/UpLoad.png\" CausesValidation=\"true\" />");
            }
            else if (drv["DdlRefColumnId"].ToString() == string.Empty && drv["DisplayName"].ToString().ToLower() == "imagebutton")
            {
                if (drv["DataTypeSqlName"].ToString().ToLower() == "varbinary")
                {
                    sb.Append(Environment.NewLine);
                    sb.Append(sIndent + "	<asp:Panel id=\"c" + cName + "Pan\" CssClass=\"DocPanel\" Style=\"display: none;\" runat=\"server\">" + Environment.NewLine);
                    sb.Append(sIndent + "	<table width=\"100%\"><tr>" + Environment.NewLine);
                    sb.Append(sIndent + "	<td><asp:FileUpload id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Fi\" runat=\"server\" /></td>" + Environment.NewLine);
                    //sb.Append(sIndent + "	<td><asp:Button id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Del\" CssClass=\"BtnImgDel\" style=\"display:none; margin-left: 6px;\" OnClientClick='NoConfirm();' Text=\"Delete\" runat=\"server\" /></td>" + Environment.NewLine);
                    sb.Append(sIndent + "	<td><asp:ImageButton ImageUrl=\"~/images/Btrash.gif\" ID=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Del\" CssClass=\"BtnImgDel\" style=\"display:none; margin-left: 6px;\" OnClientClick='NoConfirm();' Text=\"Delete\" runat=\"server\" /></td>" + Environment.NewLine);
                    sb.Append(sIndent + "	</tr></table>" + Environment.NewLine);
                    sb.Append(sIndent + "	</asp:Panel>" + Environment.NewLine);
                    sb.Append(sIndent + "	<asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" CssClass=\"DocView\" OnClientClick='NoConfirm(); return false;' OnClick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click\" runat=\"server\" />" + Environment.NewLine);
                    sb.Append(sIndent + "	<asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo\" OnClientClick='NoConfirm(); switchStatus($(this)); return false;' onclick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo_Click\" runat=\"server\" ImageUrl=\"~/Images/UpLoad.png\" CausesValidation=\"false\" />");
                }
                else if (!string.IsNullOrEmpty(drv["ColumnId"].ToString()))
                {
                    sb.Append(Environment.NewLine);
                    sb.Append(sIndent + "	<asp:TextBox id=\"c" + cName + "Div\" CssClass=\"inp-txt\" Visible=\"false\" runat=\"server\" />" + Environment.NewLine);
                    sb.Append(sIndent + "	<asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" OnClientClick='NoConfirm()' OnClick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click\" runat=\"server\" />" + Environment.NewLine);
                    sb.Append(sIndent + "<asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo\" OnClientClick='NoConfirm()' onclick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Tgo_Click\" runat=\"server\" ImageUrl=\"~/Images/UpLoad.png\" CausesValidation=\"true\" />");
                }
                else
                {
                    sb.Append("<asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" OnClientClick='NoConfirm()' OnClick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click\" runat=\"server\" />");
                }
            }
            else
            {
                if (drv["DisplayName"].ToString() == "Signature") { sb.Append("<rcasp:Signature"); }
                else if (drv["DisplayMode"].ToString() == "EncryptedTextBox") { sb.Append("<rcasp:EncryptedTextBox"); }
                else if (drv["DisplayMode"].ToString() == "OTPTextBox") { sb.Append("<rcasp:OTPTextBox"); }
                else if (drv["DisplayName"].ToString() == "ComboBox") { sb.Append("<rcasp:ComboBox autocomplete=\"off\""); }
                else if (drv["DisplayName"].ToString() == "Button") { sb.Append("<asp:Button"); }
                else if (drv["DisplayName"].ToString() == "Editor") { sb.Append("<ajwced:Editor NoScript=\"true\" ActiveMode=\"Html\""); }
                else { sb.Append("<asp:" + drv["DisplayName"].ToString()); }
                if (drv["DisplayName"].ToString() == "Signature") { sb.Append(" ShowSaveButton=\"false\""); }
                if (drv["DisplayMode"].ToString() == "Password" || drv["DisplayMode"].ToString() == "MultiLine") { sb.Append(" TextMode=\"" + drv["DisplayMode"].ToString() + "\" autocomplete=\"new-password\""); }
                if (drv["DisplayName"].ToString() == "ListBox") { sb.Append(" SelectionMode=\"Multiple\""); }
                sb.Append(" id=\"c" + cName + "\"");
                if (",Button,Label,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") < 0 || !string.IsNullOrEmpty(drv["ColumnId"].ToString()))
                {
                    sb.Append(" CssClass=");
                    if (drv["DisplayName"].ToString() == "Signature") { sb.Append("\"SignControl\""); }
                    else if (",HyperLink,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        if (drv["ColumnJustify"].ToString() == "L") { sb.Append("\"inp-txtln\""); }
                        else if (drv["ColumnJustify"].ToString() == "R") { sb.Append("\"inp-numln\""); }
                        else { sb.Append("\"inp-ctrln\""); }
                    }
                    else if (",Calendar,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("\"calendar\""); }
                    else if (",DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("\"GrdTxt\""); }
                    else if (",ListBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0) { sb.Append("\"inp-pic\""); }
                    else if (drv["DisplayName"].ToString() == "CheckBox") { sb.Append("\"inp-chk\""); }
                    else if (",AutoComplete,ComboBox,ComboBoxNoPunc,DropDownList,ListBox,DataGridLink,Document,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0) { sb.Append("\"inp-ddl\""); }
                    else if (drv["ColumnJustify"].ToString() == "L") { sb.Append("\"inp-txt\""); }
                    else if (drv["ColumnJustify"].ToString() == "R") { sb.Append("\"inp-num\""); }
                    else { sb.Append("\"inp-ctr\""); }
                }
                else if (drv["DisplayName"].ToString() == "Button") { sb.Append(" CssClass=\"small blue button\""); }
                else if (drv["DisplayName"].ToString() == "Label") { sb.Append(" CssClass=\"inp-lab\""); }
                if (",DataGrid,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                {
                    sb.Append(" AllowPaging=\"true\"");
                    sb.Append(" EnableViewState=\"true\" OnPageIndexChanged=\"c" + cName + "_PageIndexChanged\" AutoGenerateColumns=\"false\" ShowHeader=\"false\" runat=\"server\">" + Environment.NewLine);
                    sb.Append(sIndent + "<PagerStyle visible=\"true\" mode=\"NumericPages\" /><Columns><asp:TemplateColumn><ItemTemplate>" + Environment.NewLine);
                    if (",DataGridLink,".IndexOf("," + drv["DisplayMode"].ToString() + ",") >= 0)
                    {
                        sb.Append(sIndent + "<asp:HyperLink text='<%# DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\").ToString() %>' NavigateUrl=\"#\" onclick='<%# RO.Common3.Utils.AddTilde(GetUrlWithQSHash(DataBinder.Eval(Container.DataItem,\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\").ToString())) %>' CssClass=\"GrdNwrLn\"");
                        sb.Append(" width=\"100%\" runat=\"server\" />" + Environment.NewLine);
                    }
                    sb.Append(sIndent + "</ItemTemplate></asp:TemplateColumn></Columns></asp:DataGrid>");
                }
                else
                {
                    if (",ComboBox,DropDownList,ListBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        if (drv["DisplayMode"].ToString() == "AutoComplete") { sb.Append(" Mode=\"A\""); }
                        if (drv["DisplayName"].ToString() == "ComboBox")
                        {
                            sb.Append(" OnPostBack=\"cbPostBack\" OnSearch=\"cb" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\"");
                        }
                        if (drv["ColumnName"].ToString() != string.Empty) { sb.Append(" DataValueField=\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "\" DataTextField=\"" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Text\""); }
                    }
                    else if (drv["DisplayName"].ToString() == "TextBox")
                    {
                        if (drv["DataTypeSqlName"].ToString().IndexOf("Char") >= 0 && drv["DisplayMode"].ToString() != "MultiLine" && drv["ColumnLength"].ToString() != string.Empty && drv["ColumnLength"].ToString() != "0" && drv["ColumnLength"].ToString().IndexOf("-") < 0)
                        {
                            sb.Append(" MaxLength=\"" + drv["ColumnLength"].ToString() + "\"");
                        }
                    }
                    if ((drv["PwdOvride"].ToString() == "Y" || drv["ColPostBack"].ToString() == "Y") && drv["ColumnIdentity"].ToString() != "Y" && ",CheckBox,Calendar,TextBox,ComboBox,DropDownList,ListBox,Button,ImageButton,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                    {
                        if (",ComboBox,DropDownList,ListBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        {
                            sb.Append(" AutoPostBack=\"true\" OnSelectedIndexChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectedIndexChanged\"");
                            if (drv["DisplayName"].ToString() == "ComboBox")
                            {
                                sb.Append(" OnTextChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged\" OnDDFindClick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_DDFindClick\"");
                            }
                        }
                        else if (",CheckBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        {
                            sb.Append(" AutoPostBack=\"true\" OnCheckedChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_CheckedChanged\"");
                        }
                        else if (",Calendar,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        {
                            sb.Append(" OnSelectionChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_SelectionChanged\"");
                        }
                        else if (",Button,PlaceHolder,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        {
                            // AutoPostBack not available for Button and ImageButton:
                            sb.Append(" OnClick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_Click\"");
                        }
                        else
                        {
                            sb.Append(" AutoPostBack=\"true\" OnTextChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "_TextChanged\"");
                        }
                    }
                    if (drv["DisplayMode"].ToString() == "AutoListBox") sb.Append(" searchable ");
                    sb.Append(" runat=\"server\" />");
                    if (drv["DisplayMode"].ToString() == "AutoListBox") { sb.Append("<asp:TextBox ID=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Hidden\" runat=\"server\" style=\"display:none\" />"); };
                    if (drv["DataTypeSqlName"].ToString().IndexOf("Char") >= 0 && drv["DisplayMode"].ToString() == "MultiLine" && drv["ColumnLength"].ToString() != string.Empty && drv["ColumnLength"].ToString() != "0" && drv["ColumnLength"].ToString().IndexOf("-") < 0)
                    {
                        sb.Append("<asp:RegularExpressionValidator ControlToValidate=\"c" + cName + "\" display=\"none\" ErrorMessage=\"" + drv["ColumnName"].ToString() + " <= " + drv["ColumnLength"].ToString() + " characters please.\" ValidationExpression=\"^[\\s\\S]{0," + drv["ColumnLength"].ToString() + "}$\" runat=\"server\" />");
                    }
                    if (drv["ColumnIdentity"].ToString() != "Y")
                    {
                        if (drv["RequiredValid"].ToString() == "Y" && ",DropDownList,ComboBox,TextBox,ListBox,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
                        {
                            sb.Append("<asp:RequiredFieldValidator id=\"cRFV" + cName + "\" ControlToValidate=\"c" + cName + (drv["DisplayMode"].ToString() == "AutoListBox" ? "Hidden" : "") + "\" display=\"none\" runat=\"server\" />");
                        }
                        if (drv["MaskValid"].ToString() != string.Empty && drv["DisplayName"].ToString() == "TextBox")
                        {
                            sb.Append("<asp:RegularExpressionValidator id=\"cREV" + cName + "\" ControlToValidate=\"c" + cName + "\" display=\"none\" ValidationExpression=\"" + drv["MaskValid"].ToString() + "\" runat=\"server\" />");
                        }
                        if (drv["RangeValidType"].ToString() != string.Empty && drv["DisplayName"].ToString() == "TextBox")
                        {
                            sb.Append("<asp:RangeValidator id=\"cRV" + cName + "\" ControlToValidate=\"c" + cName + "\" display=\"none\" MaximumValue=\"" + drv["RangeValidMax"].ToString() + "\" MinimumValue=\"" + drv["RangeValidMin"].ToString() + "\" Type=\"" + drv["RangeValidType"].ToString() + "\" runat=\"server\" />");
                        }
                    }
                    if (PopTextBox(drv))
                    {
                        sb.Append("<asp:Image id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "E\" ImageUrl=\"~/images/Expand.gif\" CssClass=\"r-icon show-expand-button\" runat=\"server\" />");
                    }
                }
                if (drv["ColumnLink"].ToString() != string.Empty && drv["ColumnLink"].ToString().IndexOf(".") >= 0 && drv["DisplayMode"].ToString().ToLower() != "upload")
                {
                    sb.Append("<asp:ImageButton id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search\" CssClass=\"r-icon\" onclick=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Search_Click\" runat=\"server\" ImageUrl=\"~/Images/");
                    if (drv["ColumnLink"].ToString().ToLower().IndexOf("upload") >= 0) { sb.Append("UpLoad.png\""); } else { sb.Append("Link.gif\""); }
                    sb.Append(" CausesValidation=\"true\" />");
                }
            }
            if (drv["PwdOvride"].ToString() == "Y" && drv["ColumnIdentity"].ToString() != "Y" && ",ComboBox,DropDownList,ListBox,RadioButtonList,".IndexOf("," + drv["DisplayName"].ToString() + ",") >= 0)
            {
                sb.Append("<asp:TextBox TextMode=\"Password\" autocomplete=\"new-password\" id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd\" CssClass=\"PwdBox\" MaxLength=\"32\" ToolTip=\"Please enter a supervisory override password to proceed!\" AutoPostBack=\"true\" OnTextChanged=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwd_TextChanged\" runat=\"server\" visible=\"false\" /><asp:Label id=\"c" + drv["ColumnName"].ToString() + drv["TableId"].ToString() + "Pwl\" CssClass=\"inp-lbl\" text=\"Invalid\" runat=\"server\" visible=\"false\" />");
            }
            sb.Append("</div>" + Environment.NewLine);
		}
	}
}